我有一个简单的 UIButton 并且想要在用户触摸它时做一些事情,但是然后将手指移到按钮之外并且不触摸屏幕。所以看起来我需要监听 UIControlEventTouchUpOutside 事件。
在我的视图控制器中,我这样做了:
UIButton *bt = [[UIButton alloc] initWithFrame:rect];
[bt setBackgroundColor:[UIColor whiteColor]];
[bt addTarget:self action:@selector(onTouchUpOutside) forControlEvents:UIControlEventTouchUpOutside];
[self.view addSubview:bt];
以及对应的动作方法:
- (void)onTouchUpOutside {
NSLog(@"touchUpOutside");
}
现在猜猜是什么?我触摸按钮,然后将手指拖到按钮外面,取消触摸屏幕并且没有记录任何消息。事实上,它会记录我发生了 UIControlEventTouchUpInside 事件,即使我的手指并没有真正位于按钮上方。似乎我可以在触摸时将手指围绕该按钮移动大约 150% 的宽度和高度,并且当我不触摸时它会告诉我手指在按钮中。但是当我把它移得很远(=足够远)时,我确实收到了“touchUpOutside”日志消息。那么这只是苹果的另一个疯狂,比如延迟 -touchesMoved 和类似的东西吗?还是我做错了什么?