自定义转换后无法识别触摸 [英] Touches not recognized after custom transition

查看:88
本文介绍了自定义转换后无法识别触摸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an issue with custom transitions on the iPad. I create a custom transition that animates correctly and seems to work (i.e. the transition occurs). However, when I arrive at the destination view controller (after executing the isLoggedIn block), the destination view controller is unresponsive (it doesn't respond to touch events). II have a feeling it has something to do with the call to [container insertSubview:toViewController.view belowSubview:fromViewController.view]; because if I call [container insertSubview:toViewController.view aboveSubview:fromViewController.view]; the touches work as expected (but you cannot see the animation, as it happens on the source view controller).

知道触摸事件未被识别的原因吗?

Any idea why the touch events aren't being recognized?

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


推荐答案

尝试从superview中删除fromView :

Try to remove fromView from superview:

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

这篇关于自定义转换后无法识别触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆