那么如何为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];
}&当我调用方法时,我只做自己的showAnimation;,但在viewDidload中,只显示一次动画,如何使anytime?,我将需要一个"while“静止吗?或者我可以在另一个空虚中?
感谢玻利维亚拉巴斯和圣克鲁斯的帮助和问候!摇滚起来!N_n的
发布于 2013-03-09 05:49:45
只需在动画完成后再次调用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-09 02:38:33
使用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您可能需要的“选项”是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,它现在应该可以工作了。
https://stackoverflow.com/questions/15300792
复制相似问题