iOS 7自定义按钮断开操作/插座
因此,我试图创建一个自定义按钮类,它周围有一个边框,边框和文本颜色将更改为1/2 alpha,按下后返回。或多或少,我有这个工作,但出于某种原因,它阻止我的按钮按到另一个视图。我不知道为什么。有人能向我解释一下这会如何破坏这一行动吗 以下是自定义按钮类的代码:iOS 7自定义按钮断开操作/插座,ios,iphone,xcode,uibutton,segue,Ios,Iphone,Xcode,Uibutton,Segue,因此,我试图创建一个自定义按钮类,它周围有一个边框,边框和文本颜色将更改为1/2 alpha,按下后返回。或多或少,我有这个工作,但出于某种原因,它阻止我的按钮按到另一个视图。我不知道为什么。有人能向我解释一下这会如何破坏这一行动吗 以下是自定义按钮类的代码: - (void)initialize{ self.layer.cornerRadius = 10.f; self.layer.borderColor = [UIColor blackColor].CGColor;
- (void)initialize{
self.layer.cornerRadius = 10.f;
self.layer.borderColor = [UIColor blackColor].CGColor;
self.layer.borderWidth = 1.0;
self.layer.masksToBounds = YES;
}
- (instancetype)init{
self = [super init];
if(self){
[self initialize];
}
return self;
}
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
[self initialize];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder{
self = [super initWithCoder:coder];
if (self) {
[self initialize];
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
// When the button is pressed the border color chage to 1/2 alpha
UIColor *transBlack = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
[self.layer setBorderColor: transBlack.CGColor];
//EDIT based on solution
[super touchesBegan:touches withEvent:event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
// When the button is pressed the border color changes back to black
[self.layer setBorderColor:[UIColor blackColor ].CGColor];
//EDIT based on solution
[super touchesEnded:touches withEvent:event];
}
我的故事板中的按钮都在一个视图中。他们每个人都应该有一个不同于其他人的新视角。我在故事板上有一段。但是当我添加代码来更改边框颜色时,它什么都不做 您是否尝试在覆盖的touchsbegind/touchsended中调用
super
根据文件:
此方法的默认实现不执行任何操作。但是UIResponder的即时UIKit子类,特别是UIView,将消息转发到响应器链上
鉴于UIButton是UIView的一个子类,那么您可能应该调用它们。请确保在完成颜色设置工作后将触摸事件传递给基类,例如:
[超级触摸开始:触摸事件:事件]代码>
及
[super-touchesend:toucheevent:event]代码>您是否尝试调用[超级触摸开始:触摸事件:事件];和[super touchesEnded:TouchwithEvent:event];除了您的自定义边界代码之外,还有这两种方法吗?我只是厌倦了它,它似乎解决了这个问题。非常感谢。