我创建了自定义 UIButton 并添加了这些方法:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.layer.backgroundColor = self.highlightedColor.CGColor;
[self setTitleColor:self.highlightedTextColor forState:UIControlStateNormal];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
self.layer.backgroundColor = [UIColor clearColor].CGColor;
[self setTitleColor:self.highlightedColor forState:UIControlStateNormal];
}
我还使用故事板,并在自定义按钮中添加了 segue 并尝试推送新的视图控制器。
但似乎触摸方法与我的 segue 冲突,并且新控制器永远不会通过按下自定义按钮出现。如果我删除-touchesBegan
和-touchesEnded
方法它工作得很好并且新的视图控制器出现。
我没有为触发 segue 添加任何代码,只需使用情节提要“箭头”。