- 将按钮放在view的底部,按钮的左边边处的
UIControlEventTouchDown
事件延迟响应。(只在真机上有此现象)
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundColor:[UIColor blueColor]];
[button setTitle:@"normal" forState:UIControlStateNormal];
[button setTitle:@"highlighted" forState:UIControlStateHighlighted];
button.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 30, [[UIScreen mainScreen] bounds].size.width, 30);
[button addTarget:self action:@selector(touchDownAction) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(touchUpInsideAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
解决办法:将window上手势的delaysTouchesBegan属性设置为NO。
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
for (UIGestureRecognizer *gesture in self.view.window.gestureRecognizers) {
NSLog(@"gesture = %@",gesture);
gesture.delaysTouchesBegan = NO;
NSLog(@"delaysTouchesBegan = %@",gesture.delaysTouchesBegan?@"YES":@"NO");
NSLog(@"delaysTouchesEnded = %@",gesture.delaysTouchesEnded?@"YES":@"NO");
}
}
如果含有导航栏,另加一句代码:
self.navigationController.interactivePopGestureRecognizer.delaysTouchesBegan = NO;