gpt4 book ai didi

iOS 7 自定义按钮损坏的 Action / socket

转载 作者:行者123 更新时间:2023-11-28 21:58:48 25 4
gpt4 key购买 nike

所以我正在尝试创建一个自定义按钮类,其周围有边框,边框和文本颜色更改为 1/2 alpha,按下后返回。或多或少我有这个工作,但由于某种原因它阻止我的按钮推送到另一个 View 。我不确定为什么。有人可以向我解释这将如何破坏 Action 吗?

这是我的自定义按钮类的代码:

- (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];
}

我的 Storyboard 中的按钮都在一个 View 中。他们每个人都应该提出一种不同于其他观点的新观点。我在 Storyboard 中有 segue。但是当我添加更改边框颜色的代码时,它什么也没做。

最佳答案

确保在完成颜色设置工作后将触摸事件传递给基类,例如:

[super touchesBegan: touches withEvent: 事件];

[super touchesEnded: touches withEvent: event];

关于iOS 7 自定义按钮损坏的 Action / socket ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25653437/

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