简体   繁体   中英

How to stop 3d touch its interrupt other touch events?

I have a view with touchesMoved event in current UIViewController , when touch move in screen it will draw something (free draw)

then I add a subView in the view and bind the UITapGestureRecognizer(set numberOfTapsRequired 2) with subview, If double click is detect I will move the UIImageView to the click position. When I try to draw again, something wrong is happen, the draw line is not smooth now (some line is not display)

Because of the 3D Touch in iPhone6s and 6s Plus, So I can't detect the tapCount in touchesEnded .What Shall I do?

The best way is stop the 3d touch while your app is launched :

As per the apple documentation you can see this here : Apple Docs

A user can turn off 3D Touch while your app is running, so read this property as part of your implementation of the traitCollectionDidChange: delegate method.

To ensure that all your users can access your app's features, branch your code depending on whether 3D Touch is available. When it is available, take advantage of 3D Touch capabilities. When it is not available, provide alternatives such as by employing touch and hold, implemented with the UILongPressGestureRecognizer class.

Refer to iOS Human Interface Guidelines for ideas on how to enhance your app's interactions for users with 3D Touch-capable devices while not leaving your other users behind.

BEST CODE:

@interface ViewController () <UIViewControllerPreviewingDelegate>
@property (nonatomic, strong) UILongPressGestureRecognizer *longPress;
For backward compatibility I’ll also add a long press gesture recogniser here. Should our sample app be run on a device without 3D Touch support, at least the preview can be brought up via a long press gesture.

We’ll check if 3D Touch is available using something like the following method. To complete the setup, I’ve also included a custom initialiser for the long press gesture.

    - (void)check3DTouch {

        // register for 3D Touch (if available)
        if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {

            [self registerForPreviewingWithDelegate:(id)self sourceView:self.view];
            NSLog(@"3D Touch is available! Hurra!");

            // no need for our alternative anymore
            self.longPress.enabled = NO;

        } else {

            NSLog(@"3D Touch is not available on this device. Sniff!");

            // handle a 3D Touch alternative (long gesture recognizer)
            self.longPress.enabled = YES;

            }
    }

    - (UILongPressGestureRecognizer *)longPress {

        if (!_longPress) {
            _longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(showPeek)];
            [self.view addGestureRecognizer:_longPress];
        }
        return _longPress;
    }

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