【问题标题】:Custom Unwind Segue Crashes with NSException in Swift在 Swift 中使用 NSException 自定义展开 Segue 崩溃
【发布时间】:2018-01-30 02:19:47
【问题描述】:

我有一个放松的转场,我想要一个自定义动画。

我有一个自定义的 segue 类:

import UIKit
import QuartzCore

class SegueFromRight: UIStoryboardSegue {

override func perform() {
    let src: UIViewController = self.source
    let dst: UIViewController = self.destination
    let transition: CATransition = CATransition()
    let timeFunc : CAMediaTimingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    transition.duration = 0.25
    transition.timingFunction = timeFunc
    transition.type = kCATransitionPush
    transition.subtype = kCATransitionFromRight
    src.navigationController!.view.layer.add(transition, forKey: kCATransition)
    src.navigationController!.pushViewController(dst, animated: false)
    }
}

我已经定义了 unwind segue:

@IBAction func unwindToGameOver(sender: UIStoryboardSegue) {
}

我在按下按钮时调用 segue:

@IBAction func backButtonPressed(_ sender: Any) {
    performSegue(withIdentifier: "unwindToGameOver", sender: self)
}

这是我用于展开转场的界面构建器:

它因“以 NSException 类型的未捕获异常终止”而崩溃

自定义转场适用于表演转场,而展开转场在我删除其类时有效。

有什么想法吗?

【问题讨论】:

    标签: ios swift storyboard segue


    【解决方案1】:

    您正在使用展开转场,而您的自定义转场正在推动。但是导航控制器中的展开 segue 将是弹出,而不是推送。

    坦率地说,现在你会使用custom transitions,而不是继承一个segue,但如果你把它改成pop,它就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 2018-05-04
      • 1970-01-01
      相关资源
      最近更新 更多