【问题标题】:Unwind from custom modal transition从自定义模态转换中放松
【发布时间】:2014-08-06 00:19:07
【问题描述】:

我为模态转场使用自定义转换,使用 UIViewControllerAnimatedTransitioning 委托实现。所有 segues 都通过 Storyboard 设置。

我有两个导航控制器,都具有单根 VC 设置。我们称它们为1st NVC1st VC2nd NVC2nd VC

1st VC采用UIViewControllerAnimatedTransitioning协议,实现简单返回animator:

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

- (id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
    return [ModalTransitionAnimator new];
}

1st VC -> 2nd NVC 发生任何转场时,1st VC 会在 prepareForSegue: 中捕获事件并分配 transitioningDelegate 以及 modalPresentationStyle,因为您无法从 IB 执行此操作:

UINavigationController* destination = (UINavigationController*)segue.destinationViewController;
destination.transitioningDelegate = self;
destination.modalPresentationStyle = UIModalPresentationCustom;

所以一切看起来都很好,我运行了一个非常酷的动画,目标控制器出现了,所有viewWillAppear:viewDidAppear: 都按正确的顺序触发。

所以现在在屏幕上,我有2nd NVC,里面有2nd VC

我点击导航栏中的“取消”按钮,在1st VC 上触发展开动作,但没有发生向后动画。我的意思是事实上2nd VC 仍在屏幕上。

显然没有人调用dismissViewControllerAnimated。我想 Storyboard 很困惑,找不到回去的路,因为 2nd NVC 最初是模态呈现的,然后其他一些控制器请求展开。你平时是怎么处理的?

【问题讨论】:

    标签: objective-c uikit uiviewanimationtransition


    【解决方案1】:

    我跟踪了 unwind 链,发现 UIKit 在状态恢复后无法找到正确的 unwind segue。在状态恢复之前,一切都运行良好。

    我手动修复它并遍历我的控制器层次结构以返回一个定义了展开操作的控制器:

    - (UIViewController*)viewControllerForUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender {
        if([NSStringFromSelector(action) hasPrefix:@"unwindToInitialViewController"]) {
            return [[((UINavigationController*)self.centerViewController) viewControllers] firstObject];
        }
    
        UIViewController* c = [super viewControllerForUnwindSegueAction:action fromViewController:fromViewController withSender:sender];
        DDLogInfo(@"%s = %@, c = %@", __PRETTY_FUNCTION__, NSStringFromSelector(action), c);
    
        return c;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多