My app has several buttons which trigger different events. The user should NOT be able to hold down several buttons. Anyhow, holding down several buttons crashes the app.
And so, I'm trying to disable multi-touch in my app.
I've unchecked 'Multiple Touch' in all the xib files, and as far as I can work out, the properties 'multipleTouchEnabled' and 'exclusiveTouch' control whether the view uses multitouch. So in my applicationDidFinishLaunching I've put this:
self.mainViewController.view.multipleTouchEnabled = NO; self.mainViewController.view.exclusiveTouch = YES;
And in each of my view controllers I've put this in the viewDidLoad
self.view.multipleTouchEnabled = NO; self.view.exclusiveTouch = YES;
However, it still accepts multiple touches. I could do something like disable other buttons after getting a touch down event, but this would be an ugly hack. Surely there is a way to properly disable multi-touch?
Click on Start > Settings > Devices > Mouse & touchpad. If your laptop is equipped with a precision touchpad, a message that reads "Your PC has a precision touchpad" will be displayed at the top of the Touchpad settings page.
If you want to disable multi touch throughout the application and don't want to write code for each button then you can simply use Appearance of button. Write below line in didFinishLaunchingWithOptions . Show activity on this post.
Open the Device Manager in Windows. Click the arrow to the left of the Human Interface Devices option in the list, to expand and show the hardware devices under that section. Find and right-click the HID-compliant touch screen device in the list. Select the Disable device option in the pop-up menu.
If you want only one button to respond to touches at a time, you need to set exclusiveTouch for that button, rather than for the parent view. Alternatively, you could disable the other buttons when a button gets the "Touch Down" event.
Here's an example of the latter, which worked better in my testing. Setting exclusiveTouch for the buttons kind-of worked, but led to some interesting problems when you moved your finger off the edge of a button, rather than just clicking it.
You need to have outlets in your controller hooked up to each button, and have the "Touch Down", "Touch Up Inside", and "Touch Up Outside" events hooked to the proper methods in your controller.
#import "multibuttonsViewController.h" @implementation multibuttonsViewController // hook this up to "Touch Down" for each button - (IBAction) pressed: (id) sender { if (sender == one) { two.enabled = false; three.enabled = false; [label setText: @"One"]; // or whatever you want to do } else if (sender == two) { one.enabled = false; three.enabled = false; [label setText: @"Two"]; // or whatever you want to do } else { one.enabled = false; two.enabled = false; [label setText: @"Three"]; // or whatever you want to do } } // hook this up to "Touch Up Inside" and "Touch Up Outside" - (IBAction) released: (id) sender { one.enabled = true; two.enabled = true; three.enabled = true; } @end
- (void)viewDidLoad { [super viewDidLoad]; for(UIView* v in self.view.subviews) { if([v isKindOfClass:[UIButton class]]) { UIButton* btn = (UIButton*)v; [btn setExclusiveTouch:YES]; } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With