UISwipeGestureRecognizer and ShareExtension: Different behaviour on iOS 12.4 and 13.0 and latest (bug or undocumented?)

对着背影说爱祢 提交于 2020-06-26 05:56:23

问题


I am creating a Share extension and faced with a strange behaviour during my tests on iOS 13.0 and later. I use UISwipeGestureRecognizer to interpret user's swiping gestures on the main view on my extension.

This simple code provides below as an example of that I want and works perfectly on 12.4 and older:

@interface ShareAndSwipeRootController ()
@end

@implementation ShareAndSwipeRootController

- (void)loadView {
    [super loadView];

    [self.view setBackgroundColor:[UIColor redColor]];
    [self.view setUserInteractionEnabled:YES];

    UISwipeGestureRecognizer *swipeUpGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUp:)];
    swipeUpGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
    [self.view addGestureRecognizer:swipeUpGestureRecognizer];

    UISwipeGestureRecognizer *swipeDownGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDown:)];
    swipeDownGestureRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
    [self.view addGestureRecognizer:swipeDownGestureRecognizer];

 };

-(void) swipeUp:(UISwipeGestureRecognizer *)recognizer {
    NSLog(@"SWIPE Up");
}

-(void) swipeDown:(UISwipeGestureRecognizer *)recognizer {
    NSLog(@"SWIPE Down");
}

@end

On iOS 13.0 and newer it logs nothing. You might check the difference on iOS Simulator for corresponding versions.

Perhaps someone solved this problem and knows what is the reason or found its description - please share the result.

Thanks.


回答1:


You need to inspect .gestureRecognizers property in order to check what went wrong or something unusual happens.

As it is a server Gesture Recognition. you need to try shouldRecognizeSimultaneouslyWith method as written below:

gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:)

If everything goes well it'll written True.




回答2:


Vlad, that code works fine on my simulator and device (13.5) but I do suggest you do it differently.

It is a bit heavy handed to implement loadView and if you do you should not call super in this method.

Why not move your code as is into viewDidLoad where you normally attach gestures? So remove loadView and do

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.view setBackgroundColor:[UIColor redColor]];
    [self.view setUserInteractionEnabled:YES];

    UISwipeGestureRecognizer *swipeUpGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUp:)];
    swipeUpGestureRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
    [self.view addGestureRecognizer:swipeUpGestureRecognizer];

    UISwipeGestureRecognizer *swipeDownGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDown:)];
    swipeDownGestureRecognizer.direction = UISwipeGestureRecognizerDirectionDown;
    [self.view addGestureRecognizer:swipeDownGestureRecognizer];

 };


来源:https://stackoverflow.com/questions/62019991/uiswipegesturerecognizer-and-shareextension-different-behaviour-on-ios-12-4-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!