Disable or prevent multitouch in Activity
The best way to work around this scenario is to use a ViewGroup
and implement the onInterceptTouchEvent
method to manually route the touch events as you see fit.
This was originally answered here:
Android multitouch! hack anyone?
Code implementing this solution (found in the comments section of the answer to the above question) is found here:
http://pastebin.com/hiE1aTCw
Disabling multitouch in android
you can use android:splitMotionEvents
or android:windowEnableSplitTouch
Disabling multi-touch on my app
To prevent this you should turn off splitMotionEvents or windowEnableSplitTouch attribute inside ViewGroup were buttons are located.
android:splitMotionEvents="false"
How to disable multi touch on entire app or just a view using SwiftUI?
No SwiftUI solution but you can use UIKit solution in SwiftUI app.
Use UIView.appearance()
. This will disable multi-touch on the whole app.
@main
struct SwiftUIDEMO: App {
init() {
UIView.appearance().isMultipleTouchEnabled = false
UIView.appearance().isExclusiveTouch = true
}
// Body View
}
Or you can also use UIViewController
touch event and maange .isUserInteractionEnabled
.
extension UIViewController {
open override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesMoved(touches, with: event)
self.view.isUserInteractionEnabled = true
}
open override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
self.view.isUserInteractionEnabled = true
}
open override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
self.view.isUserInteractionEnabled = true
}
}
How to disable multitouch?
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
Related Topics
Eclipse, Android, Scala Made Easy But Still Does Not Work
How to Replace Deprecated Android.Support.V4.App.Actionbardrawertoggle
How to Draw a Circle with Animation in Android with Circle Size Based on a Value
How to Get Ndk-Gdb Working on Android
App Not Setup: This App Is Still in Development Mode
Fcm (Firebase Cloud Messaging) Push Notification with ASP.NET
How to Start an Android Application from the Command Line
Missing Styles. Is the Correct Theme Chosen for This Layout
Libgdx Spritebatch Render to Texture
How to Create Converter for My Class in Android Retrofit Library
Padding Between Actionbar's Home Icon and Title
Access Pictures from Pictures App in My Android App
Migration from Gcm to Fcm Needed
How to Disable Night Mode in My Application Even If Night Mode Is Enable in Android 9.0 (Pie)