gpt4 book ai didi

ios - UIButton的子类可以触发segues吗?

转载 作者:行者123 更新时间:2023-11-30 12:36:20 24 4
gpt4 key购买 nike

UIButton 的子类是否可以在故​​事板中触发 segue?一旦我更改 Storyboard中按钮的自定义类,segue 就会停止工作。

我将 UIPageViewController 嵌入到 NavigationController 内的 ViewController 中。 PageController 中的 ViewController 之一有一个子类 Button,应在 NavigationController 中执行 segue。

Button子类如下:其他所有内容都仅在 Storyboard中连接

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是“ 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)
}

关于ios - UIButton的子类可以触发segues吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42820782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com