在iOS 11中,UIViewController的transitionFromViewController从不调用其完成块

时间:2017-09-28 17:20:42

标签: ios objective-c uiviewcontroller ios11

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

这使我在使视图正确转换和动画时遇到各种问题。有没有其他人遇到这种行为,和/或发现了一种解决方法?

1 个答案:

答案 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");
}];