如何为iOS 6 xcode 4.6制作任何时间动画



如何在xcode中为uiview或uiimageview制作任意时间动画,但同时当用户在应用程序中时,动画显示为任意时间,我的动画是这样的:

- (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"的问题?或者我能在另一个虚空吗?

thanks for the help &来自拉巴斯的问候圣克鲁斯-玻利维亚!!摇滚吧! !n_n '

使用块动画是UIView的一部分。《View Programming Guide for iOS》中有一个关于动画的章节。

调用

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

"option"你可能想要的是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,它现在应该工作了。

在动画完成后再次调用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];
    }]; 
}

最新更新