从iOS 11开始,UIViewController
' transitionFromViewController:toViewController:duration:options:animations:completion:
方法似乎不再调用其完成块。
以下示例代码段:
[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
}];
这使我在使视图正确转换和动画时遇到各种问题。有没有其他人遇到这种行为,和/或发现了一种解决方法?
答案 0 :(得分:0)
因此,在将toVC.view
作为子视图控制器添加到self.view
之后,我没有明确地将toVC
作为子视图添加到self
。奇怪的是,这在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");
}];