How to do continuous recirculation of UIView animation

The following code moves the image view from right to left once, but I want to do this continuously. move left and left, then go back left on the screen and repeat left again.

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; px = 0; py = 200; imageview.center=p; [UIView commitAnimations]; 
+6
source share
1 answer

Add the following lines:

 [UIView setAnimationRepeatCount: HUGE_VAL]; [UIView setAnimationRepeatAutoreverses: YES]; 

Or, if you are targeting iOS 4.0+, it’s preferable to use lock animation:

 [UIView animateWithDuration:40.0f delay:0.0f options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse | UIViewAnimationOptionBeginFromCurrentState animations: ^(void){imageview.center = CGPointMake(0, 200);} completion:NULL]; 
+25
source

Source: https://habr.com/ru/post/886071/


All Articles