在 iOS 11 中,UIViewController 的 transitionFromViewController 从不调用其完成块
In iOS 11 , UIViewController's transitionFromViewController never calls its completion block
从 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
}];
这导致我在让我的视图正确过渡和动画时遇到各种问题。是否有其他人 运行 了解此行为,and/or 发现了解决方法?
所以事实证明,在将 toVC
作为子视图控制器添加到 self
之后,我并没有明确地将 toVC.view
作为子视图添加到 self.view
。奇怪的是,这在 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 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
}];
这导致我在让我的视图正确过渡和动画时遇到各种问题。是否有其他人 运行 了解此行为,and/or 发现了解决方法?
所以事实证明,在将 toVC
作为子视图控制器添加到 self
之后,我并没有明确地将 toVC.view
作为子视图添加到 self.view
。奇怪的是,这在 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");
}];