下面的代码将图像视图从右向左移动一次,但我想连续这样做。从右向左移动,然后在屏幕外向左移回,然后再次从右向左重复。
imageview=[[UIImageView alloc] initWithFrame:CGRectMake(320, 200, 2635, 200)];
image=[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"animal" ofType:@"png"]];
[imageview setImage:image];
[self.view addSubview:imageview];
[UIView beginAnimations:@"MoveAndStrech" context:nil];
[UIView setAnimationDuration:40]; //30
[UIView setAnimationBeginsFromCurrentState:YES];
CGPoint p, b, a, c, d,e;
p.x = 0;
p.y = 200;
imageview.center=p;
[UIView commitAnimations];
添加以下行:
[UIView setAnimationRepeatCount: HUGE_VAL];
[UIView setAnimationRepeatAutoreverses: YES];
或者,如果您的目标是 iOS 4.0+,则首选基于块的动画:
[UIView animateWithDuration:40.0f
delay:0.0f
options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionBeginFromCurrentState
animations: ^(void){imageview.center = CGPointMake(0, 200);}
completion:NULL];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)