UIButton的子类是否有可能在故事板中触发segue? 一旦我在故事板中更改按钮的自定义类,segue就会停止工作。
我将UIPageViewController嵌入在NavigationController内的ViewController中。 PageController中的一个ViewControllers有一个子类Button,它应该在NavigationController中执行一个segue。
Button子类如下: 其他所有东西都只在故事板中连接
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()
}
}
答案 0 :(得分:0)
在您的子类'方法上调用超级是'超'重要=(
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)
}