检测 UIButton 上的触摸

发布于 2024-12-07 03:10:34 字数 928 浏览 1 评论 0原文

好的,这是我的视图的层次结构。

               Main View

     |---------------|---------------|

    UIView         UIView          UIView

      |             |                |

    UIButtons     UIButtons      UIButtons

如上图所示,我有标签 111,222,333 的 3 个子视图。

每个子视图包含 25 个按钮。 一次有一个视图可见,因此我可以通过标记属性隐藏其他 2 个视图。

应用程序描述:我的应用程序在按钮上有图像,并在单击按钮时显示这些图像。用户一次只能单击一个按钮,第二次单击时比较按钮的图像,如果两个按钮的图像不同,则隐藏按钮的图像,如果相同,则不隐藏。

在模拟器上一切顺利,但在设备上,如果我同时单击两个按钮,它们都会同时打开。 (而 btnClickCount 为 2)

我希望我的按钮一次只打开一个。

我已经尝试过:

  1. 我已将 multiTouch 设置为“否”。
  2. 我尝试使用 Touches Begin,但它没有用,因为我点击的是 UIButton,而不是 UIView。
  3. 我试过了

     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 :

  1. I hav set NO to multiTouch.
  2. I tried to use Touches Began, but it was of no use as m getting tap on UIButton n not on UIView.
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晚风撩人 2024-12-14 03:10:34

UIButton 有一个布尔属性“enabled”
因此,当您点击按钮时,您可以将所有其他按钮设置为

buttonName.enabled = NO;

然后,当您希望它们再次处于活动状态时,设置

buttonName.enabled = YES;

我不确定您的按钮是如何声明的,但如果它们是具有不同名称的 IBOutlet,您可以轻松地将所有名称放入一个数组中,删除活动的名称,然后枚举其余名称。

UIButton has a boolean property 'enabled'
So when you get a button click, you could set all the other buttons to

buttonName.enabled = NO;

Then, when you want them to be active again, set

buttonName.enabled = YES;

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文