我有这个交换视图控制器方法。它工作正常,除了某些东西阻塞或延迟完成块。我已将动画持续时间设置为零以进行测试,但我在设备上观察到的内容(iPhone6 + iOS8.3 64GB)是方法transitionFromViewController:toViewController:duration:options:animations:completion:被调用但是fromViewController保持在屏幕上,有一个很长的延迟(大约五秒钟),然后调用完成块,并且fromViewController最终消失并被释放。 fromViewController目前什么都不做。
还有其他人看过这种行为吗?或者知道确定主线程是否被阻止的好方法并发现阻止者是谁?
谢谢Ed。
-(void)swapFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController
{
if (!toViewController || !fromViewController)
{
NSString *exceptionMessage = [NSString stringWithFormat:@"%s - The 'to' and 'from' view controllers must not be nil.", __PRETTY_FUNCTION__];
@throw ([NSException exceptionWithName:@"Invalid View Controller Segue" reason:exceptionMessage userInfo:nil]);
}
//Sanity check
toViewController.view.alpha = 1.0f;
[fromViewController willMoveToParentViewController:nil];
[self addChildViewController:toViewController];
//Configure the toViewController view before the transistion call.
toViewController.view.frame = self.rootContainerView.bounds;
//Add view to view hierarchy animated
[self transitionFromViewController:fromViewController
toViewController:toViewController
duration:0.0f
options:UIViewAnimationOptionTransitionNone
animations:^{
fromViewController.view.alpha = 0.0f;
}
completion:^(BOOL finished)
{
[self configureConstraintsFromParentView:self.rootContainerView toChildView:toViewController.view withInset:UIEdgeInsetsZero];
//Remove fromViewController from VC hierarchy.
[fromViewController removeFromParentViewController];
//Notify the destination view controller it did move to parent.
[toViewController didMoveToParentViewController:self];
}];
}