在延迟回调中调用超级方法

时间:2017-02-09 23:57:44

标签: swift

我有一些viewcontroller类,我想要覆盖以下方法:

open func doneButton(barButtonItem: UIBarButtonItem) {
    if let somevalue = someValueInTheCode {
        dismiss(animated: true, completion: nil)
        callback(somevalue )
    }
}

我想在子类中实现动画:

internal func animate( _ cb: @escaping () -> ()) {
    if animating {
        return
    }
    self.animating = true
    UIView.animate(withDuration: C.animTimeNav / 2.0, animations: { [weak self] in
            self?.navigationController?.navigationBar.barTintColor = C.animNavColor
            self?.navigationController?.navigationBar.layoutIfNeeded()

            },completion: { _ in
                UIView.animate(withDuration: C.animTimeNav / 1.0, animations: { [weak self] in
                    self?.navigationController?.navigationBar.barTintColor = C.navigationBarColor
                    self?.navigationController?.navigationBar.layoutIfNeeded()
                    },completion: { [weak self] _ in
                        self?.animating = false
                        cb()
                })
        })
}

所以,我想要这个新的重写方法:

open override func doneButton(barButtonItem: UIBarButtonItem) {
    animate {[weak barButtonItem] in
        super.doneButton(barButtonItem: barButtonItem ?? UIBarButtonItem())
    }
}

我的问题是:

  1. 延迟调用超级方法是否正常?
  2. 如何以正确的方式捕获super

0 个答案:

没有答案