Tapping Button Too Quickly Causes "Failed to Receive System Gesture State Notification Before Next Touch"

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

Flutter: Disable Swipe to Navigate Back in iOS and Android

I have one additional point here. I was just solving this problem, but I also needed my user to be able to go back by pressing the "native" back button on the AppBar (did not want to reimplement AppBar just because of this), and I found this niche little flag: userGestureInProgress on the Navigator object, so what I use (and presume is the preferred way) is:

onWillPop: () async {
if (Navigator.of(context).userGestureInProgress)
return false;
else
return true;
},

GestureRecognizer not responding to tap

I discovered the answer after carefully combing through my code.

One of the parent views was created without supplying a frame:

While it's a noobish enough error to warrant deletion of this questions, odds are someone else will also have the same issue in the future...

Execute action when back bar button of UINavigationController is pressed

One option would be implementing your own custom back button. You would need to add the following code to your viewDidLoad method:

    - (void) viewDidLoad {
[super viewDidLoad];
self.navigationItem.hidesBackButton = YES;
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(back:)];
self.navigationItem.leftBarButtonItem = newBackButton;
}

- (void) back:(UIBarButtonItem *)sender {
// Perform your custom actions
// ...
// Go back to the previous ViewController
[self.navigationController popViewControllerAnimated:YES];
}

UPDATE:

Here is the version for Swift:

        override func viewDidLoad {
super.viewDidLoad()
self.navigationItem.hidesBackButton = true
let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Bordered, target: self, action: "back:")
self.navigationItem.leftBarButtonItem = newBackButton
}

@objc func back(sender: UIBarButtonItem) {
// Perform your custom actions
// ...
// Go back to the previous ViewController
self.navigationController?.popViewControllerAnimated(true)
}

UPDATE 2:

Here is the version for Swift 3:

        override func viewDidLoad {
super.viewDidLoad()
self.navigationItem.hidesBackButton = true
let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.plain, target: self, action: #selector(YourViewController.back(sender:)))
self.navigationItem.leftBarButtonItem = newBackButton
}

@objc func back(sender: UIBarButtonItem) {
// Perform your custom actions
// ...
// Go back to the previous ViewController
_ = navigationController?.popViewController(animated: true)
}

Top and bottom of iOS 11.1 games unresponsive to touch

Answering my own question here:

It does indeed appear that iOS11.1 changes the timing for touch events at the top and bottom of the screen. Presumably this is in order to handle the new single-swipe gestures for opening notifications and the control center. The touchesBegan events and touchesEnded events appear at almost exactly the same time.

I believe that if I did file a Radar that Apple would consider the behaviour change as-designed (and reasonably so). However, Apps that follow the pattern of processing touch events into a touch state, and then poll that touch state to detect button presses are likely to break. The approach fails because these touches get removed from the touch state immediately after being added with no opportunity for the polling code to observe them.

The best fix is probably to make input handling event-driven throughout the App. I felt that was impractical in my case due to the amount of code that would be impacted across multiple projects. My fix was to detect the situation and not allow a touchesEnded event to affect the touch state until after the App had a chance to notice that the touch had taken place.

As an aside, similar behaviour can be observed on Android if you enable Magnification Gestures in Accessibility Settings (again the OS is holding back touch events from the App until it determines that a gesture isn't taking place - in this case a triple-tap). I'm pleased that in fixing this iOS11.1 issue, I've also addressed the fact that my Android apps were incompatible with Magnification Gestures too.

How to dismiss keyboard when user tap other area outside textfield?

The below code will work on all the components in the UIView for all the UITextField

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
for (UIView * txt in self.view.subviews){
if ([txt isKindOfClass:[UITextField class]] && [txt isFirstResponder]) {
[txt resignFirstResponder];
}
}
}

OR

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}


Related Topics



Leave a reply



Submit