3

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.

Vladislav
  • 165
  • 1
  • 5
  • 15
  • looks like same issue https://stackoverflow.com/questions/56918410/ios-13-uipangesturerecognizer-behave-differently-from-ios-12 – pompopo Jun 01 '20 at 09:26

2 Answers2

0

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];

 };
skaak
  • 2,988
  • 1
  • 8
  • 16
0

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.

kartik tyagi
  • 6,256
  • 2
  • 14
  • 31