简体   繁体   中英

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.

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..........

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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