首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIButton UIControlEventTouchUpInside触发事件,即使在按钮框外接手指时也是如此

UIButton UIControlEventTouchUpInside触发事件,即使在按钮框外接手指时也是如此
EN

Stack Overflow用户
提问于 2014-03-31 09:31:41
回答 1查看 792关注 0票数 0

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

据我所知,UIControlEventTouchUpInside应该这么做,而且在大多数情况下是这样的:如果我把手指从框架拖到足够远的地方,然后再抬起它,事件就不会被触发(这就是我正在寻找的行为)。

但如果我把手指举到框架外,事件无论如何都会被触发。有什么办法可以防止吗?

代码语言:javascript
复制
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];
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-01 07:05:24

这是UIButton的默认性质。你不能改变它。

根据我所理解的按钮名称,您有计划,当使用“选择计划”时,您希望找到单击哪个按钮。

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

下面是这些事件的示例链接。

Application

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22758121

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档