UIButton的子类可以触发segue吗?



UIButton 的子类是否有可能在情节提要中触发 segue?一旦我更改情节提要中按钮的自定义类,segue 就会停止工作。

我有UIPageViewController嵌入在导航控制器内的ViewController中。页面控制器中的一个视图控制器有一个子类化的按钮,该按钮应在导航控制器中执行 segue。

按钮子类如下所示:其他所有内容仅在故事板中连接

class MiniButton:UIButton{
var originalBackgroundColor:UIColor?
var originalTextColor:UIColor?
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    originalBackgroundColor = self.backgroundColor
    originalTextColor = self.titleColor(for: .normal)
    self.backgroundColor = MiniColor.miniYellow
    self.setTitleColor(MiniColor.white, for: .normal)
}
func backToOriginalColors(){
    self.backgroundColor = originalBackgroundColor
    self.setTitleColor(originalTextColor, for: .normal)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    backToOriginalColors()
}
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
    backToOriginalColors()
}

}

在子类上调用 super' 方法"超级"重要 =(

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesBegan(touches, with: event) // <--------
    originalBackgroundColor = self.backgroundColor
    originalTextColor = self.titleColor(for: .normal)
    self.backgroundColor = MiniColor.miniYellow
    self.setTitleColor(MiniColor.white, for: .normal)
}

最新更新