- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 20, 400, 200)];
[btn setTitle:@"123" forState:UIControlStateNormal];
[btn setTitle:@"234" forState:UIControlStateHighlighted];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor grayColor]];
[btn addTarget:self action:@selector(test11) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
- (void)test11 {
NSLog(@"xxxxxxxxxxxxxx");
}
当我单击屏幕左侧的按钮时,
test11
正在工作但不是高亮。当我点击另一个区域的按钮时,test11
正在工作和高亮。不同的设备和 iOS 版本的行为不同:最佳答案
我了解问题是当您点击按钮的最左侧时,它没有显示触摸突出显示?
这是因为按钮上的触摸处理与屏幕边缘手势识别器冲突,因此在点击完成之前不会转换到已识别状态。
如果你考虑一下:
检查您的层次结构中还有哪些其他识别器处于事件状态,如果您有 UINavigationController 它默认有一个左屏幕边缘识别器用于后退手势。这通常是这个问题的罪魁祸首。如果需要,您可以禁用此识别器,或者实现它的委托(delegate)以使其与您的按钮一起玩。
关于ios - 单击屏幕左边缘的按钮时不突出显示,但触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42639508/