UIView animateWithDuration not animating in ios8

2019-06-04 04:55发布

I have implemented a custom segue class for emulating the push transition without navigation bar. The trick is to take to snapshots, add them to the view, replace the viewController, move the snapshots, and finally remove them. This emules a horizontal movement of the viewController, but actually only two UIImagesView are moved.

The following code implements this.

self.destinationImageView.frame = offsetFrameD;
self.sourceImageView.frame = offsetFrameS;

//ViewController replacement
[self.sourceViewController presentModalViewController:self.destinationViewController animated:NO];

//Overpose the snapShot who will simulate the transition between vies.
[destinationView addSubview: self.sourceImageView];
[destinationView addSubview: self.destinationImageView];

[UIView animateWithDuration:1.0
                      delay:0.0
                    options:UIViewAnimationOptionCurveEaseOut
                 animations:^{
                     self.destinationImageView.frame = self.finalFrameD;
                     self.sourceImageView.frame = self.finalFrameS;
                 }
                 completion:^(BOOL finished) {
                     [self.sourceImageView removeFromSuperview];
                     [self.destinationImageView removeFromSuperview];
                 }];

This code worked with iOS 7. However, when using iOS 8, it seems like the animation is not performed. The destinationImageView and sourceImageView are directly moved to the finalPosition (WITHOUT ANIMATING) and the completion block is not called, so both UIImageView are not finally removed.

Does anyone knows how the animation should be performed with iOS 8?

2条回答
欢心
2楼-- · 2019-06-04 05:08

Use the following line of code before the start of the animation:

[UIView setAnimationsEnabled:YES];
查看更多
祖国的老花朵
3楼-- · 2019-06-04 05:18

You should adjust the auto layout constraints and not the frames position. Have a look at this solution. I hope it helps. UIView transitionWithView & setting the frame no longer works iOS8

查看更多
登录 后发表回答