1

I have left and right navigation bar buttons on navigation bar, both can be tapped at the same time, and their action gets fired, How can I prevent multiple touch. I have searched over here and google, but no success

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
zaheer
  • 893
  • 13
  • 27
  • 1
    Have a look here: http://stackoverflow.com/questions/1080043/how-to-disable-multitouch – TheEye Feb 24 '14 at 08:08
  • I have already checked this, but no success. – zaheer Feb 24 '14 at 08:11
  • I created the UIBarButtonItem in storyboard, and put this work around to set exclusive touch – zaheer Feb 24 '14 at 09:15
  • I created the UIBarButtonItems in storyboard and put these lines in viewDidDLoad for(UIView *temp in self.navigationController.navigationBar.subviews) { [temp setExclusiveTouch:YES]; } This solved the problem – zaheer Feb 24 '14 at 09:16

3 Answers3

1

You can also use -setExclusiveTouch on each of the buttons so that only one will register at a time. You don't need to disable multi-touch on your view either.

Ayaz
  • 1,398
  • 15
  • 29
1

Pretty much simple you can use make use of ExclusiveTouch property in this case

[self.navigationController.navigationBar setExclusiveTouch:YES];

This is a Boolean value that indicates whether the receiver handles touch events exclusively.

Setting this property to YES causes the receiver to block the delivery of touch events to other views in the same window. The default value of this property is NO.

Ash
  • 5,525
  • 1
  • 40
  • 34
0

There is a property called exclusiveTouch for UIButton. Create a navigation button using that like so:

Eg:

UIButton *btnAdd = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 38, 37)];
[btnAdd setContentMode:UIViewContentModeScaleAspectFit];
[btnAdd setBackgroundImage:[UIImage imageNamed:@"abc.png"] forState:UIControlStateNormal];
[btnAdd addTarget:selfaction:@selector(<method>) forControlEvents:UIControlEventTouchUpInside];
[btnAdd setExclusiveTouch:YES];
UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc] initWithCustomView:btnAdd];
self.navigationItem.rightBarButtonItem = rightBtn;
Anil
  • 2,430
  • 3
  • 37
  • 55