UIView animateWithDuration不在ios8中animation

我已经实现了一个自定义的segue类来模拟没有导航栏的push过渡。 诀窍是采取快照,将它们添加到视图,replaceviewController,移动快照,并最终删除它们。 这模仿了viewController的水平移动,但实际上只有两个UIImagesView被移动。

下面的代码实现了这一点。

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]; }]; 

此代码与iOS 7一起工作。但是,使用iOS 8时,似乎不执行animation。 destinationImageView和sourceImageView直接移动到finalPosition(WITHOUT ANIMATING)并且完成块没有被调用,所以两个UIImageView都没有被最终删除。

有谁知道应该如何使用iOS 8执行animation?

您应该调整自动布局约束,而不是帧位置。 看看这个解决scheme。 我希望它有帮助。 UIView transitionWithView&设置框架不再适用iOS8

在animation开始之前使用以下代码行:

 [UIView setAnimationsEnabled:YES];