0

那么如何为 UIViews 或 xcode 中的 UIImageViews 制作任何时间动画,但意味着当用户在应用程序中时,动画显示的任何时间,我的动画是这样的:

- (void)showAnimation
{


    [UIImageView beginAnimations:@"EFFECT_SHOW" context:nil];
    [UIImageView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIImageView setAnimationDuration:5.0f];

    self.imageAnimation.frame = CGRectMake(400, imageAnimation.frame.origin.y, imageAnimation.frame.size.width, imageAnimation.frame.size.height);
    self.imageAnimation2.frame = CGRectMake(-400, imageAnimation2.frame.origin.y, imageAnimation2.frame.size.width, imageAnimation2.frame.size.height);

    [UIImageView commitAnimations];
}

&当我调用方法时,我只是做 [self showAnimation];,但是在 viewDidload 中,只显示一次动画,如何随时制作?,我需要一个“while”问题吗?或者我可以在另一个虚空中吗?

感谢拉巴斯和圣克鲁斯德拉谢拉 - 玻利维亚的帮助和问候!摇滚吧!!!n_n'

4

2 回答 2

2

使用属于UIView. iOS的View Programming Guide有一个很棒的动画部分。

调用方法时

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

您可能想要的“选项”是UIViewAnimationOptionAutoreverse.

例如:

[UIView animateWithDuration:5.0f delay:0 options:UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat animations:^{
    self.imageAnimation.frame = CGRectMake(400, imageAnimation.frame.origin.y, imageAnimation.frame.size.width, imageAnimation.frame.size.height);
    self.imageAnimation2.frame = CGRectMake(-400, imageAnimation2.frame.origin.y, imageAnimation2.frame.size.width, imageAnimation2.frame.size.height);
} completion:nil];

编辑:是的..这是我的错,它不会重复。根据文档......

UIViewAnimationOptionAutoreverse

前后运行动画。必须与UIViewAnimationOptionRepeat选项结合使用。

我更新了代码以包含UIViewAnimationOptionRepeat它,它现在应该可以工作了。

于 2013-03-08T18:38:32.727 回答
0

动画完成后再次调用showAnimation方法即可

 - (void) showAnimation
{
    //TODO: maybe reset you animation
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView animateWithDuration:5.0f animations:^(){
            // define animation
            self.imageAnimation.frame = CGRectMake(400, imageAnimation.frame.origin.y, imageAnimation.frame.size.width, imageAnimation.frame.size.height);
            self.imageAnimation2.frame = CGRectMake(-400, imageAnimation2.frame.origin.y, imageAnimation2.frame.size.width, imageAnimation2.frame.size.height);
        }
        completion:^(BOOL finished){
            // after the animation is completed call showAnimation again
            [self showAnimation];
    }]; 
}
于 2013-03-08T21:49:44.523 回答