简体   繁体   English

检测UIButton上的Touch

[英]detect Touch on UIButton

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. 如上图所示,我有3个标签111,222,333的子视图。

And Each Sub-view contains 25 buttons. 每个子视图包含25个按钮。 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. 应用说明:我的应用在按钮上具有图像,而m在单击按钮时显示这些图像。 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) (而btnClickCount为2时)

i want my button to open only one at a time. 我希望我的按钮一次只能打开一个。

What i have tried : 我试过的

  1. I hav set NO to multiTouch. 我已将multiTouch设置为NO。
  2. I tried to use Touches Began, but it was of no use as m getting tap on UIButton n not on UIView. 我尝试使用Touches Began,但没有用,因为m可以点击UIButton n而不可以点击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.......... 请帮助,在此先谢谢..........

UIButton has a boolean property 'enabled' So when you get a button click, you could set all the other buttons to UIButton的布尔属性为“ enabled”,因此单击按钮时,可以将所有其他按钮设置为

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. 我不确定您的按钮如何声明,但是如果它们是具有不同名称的IBOutlet,则可以轻松地通过将所有名称放入一个数组中,删除活动的名称,然后对其余名称进行枚举来轻松实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM