【问题标题】:Custom UIStoryboardSegue on back button press?按下后退按钮时自定义 UIStoryboardSegue?
【发布时间】:2016-10-04 00:12:13
【问题描述】:

我有一个自定义 UIStoryboardSegue 可以“缩放”UIImageView。现在我还需要一个自定义的UIStoryboardSegue,当用户按下UINavigationController 中的后退按钮时它会“缩小”。这几天我一直在尝试这样做,但没有成功。

我对@9​​87654326@ 进行了子类化,并在其中添加了以下代码:

- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier {

    UIStoryboardSegue *theSegue;

    NSLog(@"Unwind called");

    if ([fromViewController isKindOfClass:[SetDetailViewController class]]) {
        theSegue = [ZoomOutSegue segueWithIdentifier:identifier source:fromViewController destination:toViewController performHandler:^(void){}];
    } else {
        theSegue = [super segueForUnwindingToViewController:toViewController fromViewController:fromViewController identifier:identifier];
    }

    return theSegue;
}

但是,这没有被调用。我在这里做错了什么?

【问题讨论】:

  • 你继承 UINavigationController 的原因是什么?
  • 你想从模型 viewController 中放松吗?
  • 不,来自推送的视图控制器
  • 那么就不需要继承UINavigationController了。所以从放弃子类开始。其次,您是否将展开转场连接到实际按钮?

标签: ios objective-c uinavigationcontroller uistoryboardsegue


【解决方案1】:
  1. 我假设您仍在通过缩放切换视图
  2. 我是 Swiftie,所以我的帮助将来自 Swift

您应该能够通过使您的类成为导航控制器的委托,然后使用导航控制器的willShowViewController 方法来捕获这些事件

  • 在定义类时将UINavigationControllerDelegate 添加到类中
  • viewDidLoad() 函数下添加self.navigationController?.delegate = self
  • 现在您应该能够使用将在导航控制器切换到新视图控制器之前运行的函数(所以是的,它也会在按下后退按钮时运行)。在 Swift 中它看起来像这样:

    func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
    
    //if the view controller we are going to is one we want to trigger this action
    if let _ = viewController as? ViewController {
        //perform the thing you want here
    }}
    

【讨论】:

    猜你喜欢
    • 2016-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-20
    相关资源
    最近更新 更多