UIView animateWithDuration not animating in ios8

房东的猫 提交于 2019-12-23 01:16:23

问题


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?


回答1:


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




回答2:


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

[UIView setAnimationsEnabled:YES];


来源:https://stackoverflow.com/questions/26277109/uiview-animatewithduration-not-animating-in-ios8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!