简体   繁体   中英

Image Animation stops automatically when the device orientation changes

I am new to iPhone development. I have an image view in my nib which I am successfully animating, making it to move from bottom to top using the following code.

- (void)viewWillAppear:(BOOL)animated{ 
    [super viewWillAppear:YES];

    [self animateImage];    
}

-(void)animateImage{

    CGRect oldFrame=self.displayImg.frame;

     [UIView animateWithDuration:2.0 animations:^{

     CGRect newFrame=self.displayImg.frame;

      newFrame=CGRectOffset(newFrame, 0, -420);

      self.displayImg.frame=newFrame;

    }completion:^(BOOL finished){

        if(finished){

            self.displayImg.frame=oldFrame;

            [self animateImage];            
         }
    }];
}

My problem is when I change the device orientation to Landscape the image animation stops and image disappears. Any help on this ?

It works just fine, the recursion is not interrupted and the animation continues. It means you are doing something yourself interrupting it if the recursion really stops or changing the view content/initial position so that you can't see it anymore while the animation is still working.

no, it doesn't buddy. I checked it myself. It works fine. Work around, mistake be somewhere else in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM