0

我想實現像iOS 8郵件應用程序swipeable「新電子郵件」viewController過渡。這一切都工作正常,除了一件事 - 當「新電子郵件」vc(第二個vc)放置在屏幕的底部 - 第一個viewController是無效的。我的代碼(不包括animateTransition:):通話finishInteractiveTransition後 - 黑屏

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented 
                    presentingController:(UIViewController *)presenting 
                    sourceController:(UIViewController *)source { 
    return self; 
} 

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{ 
    return self; 
} 

- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id <UIViewControllerAnimatedTransitioning>)animator{ 
    return nil; 
} 

- (id <UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id <UIViewControllerAnimatedTransitioning>)animator{ 
    return self; 
} 

#pragma mark - UIViewControllerInteractiveTransitioning 

- (void)startInteractiveTransition:(id <UIViewControllerContextTransitioning>)transitionContext { 
    self.transitionContext = transitionContext; 
    [self updateInteractiveTransition:0.0]; 
} 

#pragma mark - UIPercentDrivenInteractiveTransition 

- (void)updateInteractiveTransition:(CGFloat)percentComplete{ 
    NSLog(@"updateInteractiveTransition:%f", percentComplete); 

    if (percentComplete < 0) { 
     percentComplete = 0; 
    } 
    else if (percentComplete > 1){ 
     percentComplete = 1; 
    } 

    UIViewController *modalVC = [self.transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    UIViewController *nonModalVC = [self.transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 

    float scaleFactor = 0.9 + 0.1 * percentComplete; 
    float alphaVal = 0.5 + 0.5 * percentComplete; 
    nonModalVC.view.transform = CGAffineTransformScale(CGAffineTransformIdentity, scaleFactor, scaleFactor); 
    nonModalVC.view.alpha = alphaVal; 


    CGRect modalVCFrame = modalVC.view.frame; 
    modalVCFrame.origin.y = percentComplete * viewH + kModalViewYOffset; 
    modalVC.view.frame = modalVCFrame; 
} 

- (void)cancelInteractiveTransitionWithDuration:(CGFloat)duration{ 
    NSLog(@"cancelInteractiveTransitionWithDuration"); 


    UIViewController *modalVC = [self.transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    UIViewController *nonModalVC = [self.transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 

    CGRect modalVCFrame = modalVC.view.frame; 
    modalVCFrame.origin.y = self.cancelUp ? kModalViewYOffset : viewH - kModalViewNavBarHeight; 
    NSLog(@"modalVCFrame.origin.y = %f", modalVCFrame.origin.y); 
    CGAffineTransform transformVal = self.cancelUp ? 
               CGAffineTransformMakeScale(kNonModalViewMinScale, kNonModalViewMinScale) 
               : CGAffineTransformIdentity; 
    CGFloat alphaVal = self.cancelUp ? 0.5 : 1.0; 

    [UIView animateWithDuration:duration animations:^{ 
     modalVC.view.frame = modalVCFrame; 
     nonModalVC.view.transform = transformVal; 
     nonModalVC.view.alpha = alphaVal; 
    } completion:^(BOOL finished) { 
     [self cancelInteractiveTransition]; 
    }]; 

    reversed = NO; 
} 


- (void)finishInteractiveTransitionWithDuration:(CGFloat)duration{ 

    UIViewController *modalVC = [self.transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    UIViewController *nonModalVC = [self.transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 

    CGRect modalVCFrame = modalVC.view.frame; 
    modalVCFrame.origin.y = viewH ; //+ kModalViewNavBarHeight; 

    [UIView animateWithDuration:duration animations:^{ 
     modalVC.view.frame = modalVCFrame; 
     nonModalVC.view.transform = CGAffineTransformIdentity; 
     nonModalVC.view.alpha = 1.0; 
    } completion:^(BOOL finished) { 

     [modalVC.view removeFromSuperview]; 
     [self.transitionContext completeTransition:YES]; 
     self.transitionContext = nil; 

     [self finishInteractiveTransition]; 

    }]; 

    reversed = NO; 
} 

如果我修改startInteractiveTransition方法這樣

- (void)startInteractiveTransition:(id <UIViewControllerContextTransitioning>)transitionContext { 
    NSLog(@"startInteractiveTransition"); 

    self.transitionContext = transitionContext; 

    UIViewController *modalVC = [self.transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    UIViewController *nonModalVC = [self.transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 
    UIView *containerView = [self.transitionContext containerView]; 
    [containerView insertSubview:nonModalVC.view belowSubview:modalVC.view]; 

    [self updateInteractiveTransition:0.0]; 
} 

然後第一的viewController將被激活,如果將第二放置在底部,但在關閉secondVC - 出現黑屏。問題在於解僱,我們無法向內容視圖添加任何內容,因爲原始演示者仍然存在,並且將通過刪除容器視圖來顯示。但是,如何在第二VC底部時做出firstVC響應呢?

回答

0

解決了我的問題。首先 - 在解散時不要向containerView添加任何東西。其次 - 當modalView放置在底部時,使containerView「傳遞」通過自身觸及。爲此,我爲UIView添加了類別並覆蓋了hitTest:withEvent:方法