1

我有这个交换视图控制器方法。它工作正常,除了某些东西正在阻塞或延迟完成块。我已将动画持续时间设置为零以进行测试,但我在设备(iPhone6+ iOS8.3 64GB)上观察到的是方法 transitionFromViewController:toViewController:duration:options:animations:completion: 被调用但 fromViewController 仍然存在在屏幕上,有很长的延迟(大约 5 秒),然后调用完成块,fromViewController 最终消失并被释放。此时 fromViewController 什么也不做。

有没有其他人看到过这种行为?或者知道确定主线程是否被阻塞并发现阻塞者是谁的好方法?

谢谢埃德。

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

4

0 回答 0