使用UIViewControllerAnimatedTransition时,toView按钮无法与之交互

时间:2017-02-01 18:23:41

标签: ios objective-c uiviewcontroller segue transition

我正在使用自定义UIViewControllerAnimatedTransitioning类来解决此问题。完成动画并显示toView后,其中的元素(按钮等)无法接收交互。

自定义类代码如下:

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
    return 1.0;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext;
{
    UIViewController *fromViewController = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toViewController = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    CGRect finalFrameForVC = [transitionContext finalFrameForViewController:toViewController];
    UIView *containerView = [transitionContext containerView];
    CGRect bounds = [[UIScreen mainScreen] bounds];
    toViewController.view.frame = CGRectMake(0, 0, bounds.size.width, 0);
    [containerView addSubview:toViewController.view];

    [UIView animateWithDuration:[self transitionDuration:transitionContext] delay:0.0 usingSpringWithDamping:1.0 initialSpringVelocity:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
        fromViewController.view.alpha = 0.5;
        toViewController.view.frame = CGRectMake(0, 0, finalFrameForVC.size.width, finalFrameForVC.size.height);
    } completion:^(BOOL finished) {
        fromViewController.view.alpha = 0.0;
    }];
}

从视图来看,过渡被称为:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"showAction"]) {
        FiltersViewController *filterView = (FiltersViewController *)segue.destinationViewController;
        filterView.transitioningDelegate = self;
    }
}

-(id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
    self.filtersPresentAnimationController = [[FiltersPresentAnimationController alloc] init];
    return self.filtersPresentAnimationController;
}

知道我做错了什么吗?当我从segue中删除segue标识符时,它完全正常。

1 个答案:

答案 0 :(得分:0)

我忘了告诉transitionContext过渡完成了。

在完成的动画块中错过了这个

[transitionContext completeTransition:YES];