以下代码将图像视图从右向左移动一次,但我想继续进行。向右移动到左边然后再向左移动,再次从右向左重复。
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];
答案 0 :(得分:25)
添加以下行:
[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];