从 iOS 11 开始,UIViewController
的transitionFromViewController:toViewController:duration:options:animations:completion:
方法似乎不再调用其完成 block 。
下面的示例代码片段:
[self addChildViewController:toVC];
[fromVC willMoveToParentViewController:nil];
[self transitionFromViewController:fromVC
toViewController:toVC
duration:0.4
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{}
completion:^(BOOL finished) {
NSLog(@"Completion called"); // this completion is never executed
}];
这导致我在让我的 View 正确转换和动画时遇到各种问题。有没有其他人遇到过这种行为,和/或发现了一种解决方法?
最佳答案
所以事实证明我没有明确添加 toVC.view
作为 self.view
的 subview 添加后toVC
作为 self
的 subview Controller .奇怪的是,这在 iOS 11 与以前的版本中表现不同,但这确实起到了作用:
[self addChildViewController:toVC];
[self.view addSubview:toVC.view]; // This line is what is needed
[fromVC willMoveToParentViewController:nil];
[self transitionFromViewController:fromVC
toViewController:toVC
duration:0.4
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{}
completion:^(BOOL finished) {
NSLog(@"Completion called");
}];
关于ios - 在 iOS 11 中,UIViewController 的 transitionFromViewController 从不调用它的完成 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46474965/