我需要在我的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];发布于 2014-04-01 07:05:24
这是UIButton的默认性质。你不能改变它。
根据我所理解的按钮名称,您有计划,当使用“选择计划”时,您希望找到单击哪个按钮。
为了更准确地使用touchesBegan和touchesEnd事件,我会说。
下面是这些事件的示例链接。
Application
https://stackoverflow.com/questions/22758121
复制相似问题