检测 UIButton 上的触摸
好的,这是我的视图的层次结构。
Main View
|---------------|---------------|
UIView UIView UIView
| | |
UIButtons UIButtons UIButtons
如上图所示,我有标签 111,222,333 的 3 个子视图。
每个子视图包含 25 个按钮。 一次有一个视图可见,因此我可以通过标记属性隐藏其他 2 个视图。
应用程序描述:我的应用程序在按钮上有图像,并在单击按钮时显示这些图像。用户一次只能单击一个按钮,第二次单击时比较按钮的图像,如果两个按钮的图像不同,则隐藏按钮的图像,如果相同,则不隐藏。
在模拟器上一切顺利,但在设备上,如果我同时单击两个按钮,它们都会同时打开。 (而 btnClickCount 为 2)
我希望我的按钮一次只打开一个。
我已经尝试过:
- 我已将 multiTouch 设置为“否”。
- 我尝试使用 Touches Begin,但它没有用,因为我点击的是 UIButton,而不是 UIView。
我试过了
self.view.userInteractionEnabled = NO; [self PerformSelector:@selector(EnableUserInteraction) withObject:nil afterDelay:0.5];
第一次按钮单击,但如果同时发生触摸,则不会发生任何事情,但它适用于单击。
不知道该怎么办!!!!
请帮助,提前致谢......
Ok, Here is the Hierarchy of my View.
Main View
|---------------|---------------|
UIView UIView UIView
| | |
UIButtons UIButtons UIButtons
As Above figure shows I have 3 subViews of Tag 111,222,333.
And Each Sub-view contains 25 buttons.
One view is visible at a time, so m hiding the other 2 view by tag property.
App Description: My app having images on buttons and m showing those image on click of buttons. User can be able to click only one button at a time , and on second click m comparing the images of the buttons if the two images of buttons are not same, the image of button is hided and if they are same, they r not hidden.
All is going well on simulator, but on device, if I click Two button simultaneously, they both open at same time. (while btnClickCount is 2)
i want my button to open only one at a time.
What i have tried :
- I hav set NO to multiTouch.
- I tried to use Touches Began, but it was of no use as m getting tap on UIButton n not on UIView.
I tried
self.view.userInteractionEnabled = NO; [self performSelector:@selector(EnableUserInteraction) withObject:nil afterDelay:0.5];
on first button click but if touches are occuring at same time, then nothing happens, but it is working for single tap.
dont know what to do with this !!!!!
Please Help , Thanks in advance..........
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UIButton 有一个布尔属性“enabled”
因此,当您点击按钮时,您可以将所有其他按钮设置为
然后,当您希望它们再次处于活动状态时,设置
我不确定您的按钮是如何声明的,但如果它们是具有不同名称的 IBOutlet,您可以轻松地将所有名称放入一个数组中,删除活动的名称,然后枚举其余名称。
UIButton has a boolean property 'enabled'
So when you get a button click, you could set all the other buttons to
Then, when you want them to be active again, set
I'm not sure how your buttons are declared, but if they are IBOutlets with different names, you can easily by put all the names in an array, remove the one that is active, and enumerating through the rest.