1

我对 iPad 上的自定义过渡有疑问。我创建了一个自定义过渡,它可以正确动画并且似乎可以工作(即过渡发生)。但是,当我到达目标视图控制器时(在执行 isLoggedIn 块之后),目标视图控制器没有响应(它不响应触摸事件)。我感觉它与调用有关,[container insertSubview:toViewController.view belowSubview:fromViewController.view];因为如果我调用[container insertSubview:toViewController.view aboveSubview:fromViewController.view];触摸按预期工作(但你看不到动画,因为它发生在源视图控制器上)。

知道为什么无法识别触摸事件吗?

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *container = [transitionContext containerView];

//Prepare the view
if (self.isLoggedIn) {
    //Insert the main view under the login view
    CGRect frame = CGRectMake(0, 0, toViewController.view.frame.size.height,
                              toViewController.view.frame.size.width);
    toViewController.view.frame = frame;
    [container insertSubview:toViewController.view belowSubview:fromViewController.view];
} else {
    CGRect frame = CGRectMake(0, 0, toViewController.view.frame.size.height,
                              toViewController.view.frame.size.width);
    toViewController.view.frame = frame;
    if([toViewController respondsToSelector:@selector(openWalls)]) {
        [(DJVLoginViewController*)toViewController openWalls];
    }
    if([toViewController respondsToSelector:@selector(toggleLoginViewsAlpha:)]) {
        [(DJVLoginViewController*)toViewController toggleLoginViewsAlpha:0];
    }
    //Insert the login view above the main view
    [container insertSubview:toViewController.view aboveSubview:fromViewController.view];
}

//Make animations

[UIView animateWithDuration:[self transitionDuration:transitionContext]
                 animations:^{
                     if (self.isLoggedIn) {
                         //Perform animation
                     } else {
                         //Perform animation
                     }
                 } completion:^(BOOL finished) {
                     [transitionContext completeTransition:YES];
                 }];
}
4

1 回答 1

1

尝试从superview中删除fromView:

[UIView animateWithDuration:[self transitionDuration:transitionContext]
                 animations:^{
                     if (self.isLoggedIn) {
                         //Perform animation
                     } else {
                         //Perform animation
                     }
                 } completion:^(BOOL finished) {
                     [fromViewController.view removeFromSuperview];
                     [transitionContext completeTransition:YES];
                 }];
}
于 2014-03-10T12:37:34.103 回答