UIButton UIControlEventTouchUpInside即使在按钮框外拾取手指也会触发事件

时间:2014-03-31 09:31:41

标签: ios ios7 uibutton

我的iPhone应用程序上需要一个按钮,只有当用户触摸到框架区域内时才触发该事件。

据我了解UIControlEventTouchUpInside应该这样做,而且大多数情况下它都会这样做:如果我将手指放在离屏幕足够远的屏幕上,然后只提起它,事件就不会发生。触发(这是我正在寻找的行为。)

但如果我在框架外举起手指,无论如何都会触发事件。有没有办法防止它?

UIButton *selectPlan = [UIButton buttonWithType:UIButtonTypeRoundedRect];
selectPlan.frame = CGRectMake(self.view.bounds.size.width/2-buttonWidthHeight/2, self.view.bounds.size.height/2-buttonWidthHeight/2 + 43, buttonWidthHeight, buttonWidthHeight);
[selectPlan addTarget:self action:@selector(checkIfPlansExistAndFindBestPlan) forControlEvents:UIControlEventTouchUpInside];
[selectPlan setTitle:@"Select Plan" forState:UIControlStateNormal];
[self.view addSubview:selectPlan];

1 个答案:

答案 0 :(得分:0)

这是UIButton的默认属性。你无法改变它。

从我理解的按钮名称,您有计划,并在使用时选择计划,您想要找到单击的按钮。

我会说更准确地使用touchesBegantouchesEnd事件。

以下是这些活动的示例链接。

http://www.techotopia.com/index.php/An_Example_iOS_5_iPhone_Touch,_Multitouch_and_Tap_Application

相关问题