简体   繁体   English

UISwipeGestureRecognizer 和 ShareExtension:iOS 12.4 和 13.0 和最新版本(错误或未记录?)

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

I am creating a Share extension and faced with a strange behaviour during my tests on iOS 13.0 and later.我正在创建一个共享扩展,并在 iOS 13.0 及更高版本的测试期间遇到了一个奇怪的行为。 I use UISwipeGestureRecognizer to interpret user's swiping gestures on the main view on my extension.我使用UISwipeGestureRecognizer来解释用户在我的扩展程序主视图上的滑动手势。

This simple code provides below as an example of that I want and works perfectly on 12.4 and older:这个简单的代码在下面提供了一个我想要的示例,并且可以在 12.4 及更早版本上完美运行:

@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.在 iOS 13.0 和更新版本上,它什么也不记录。 You might check the difference on iOS Simulator for corresponding versions.您可以在 iOS 模拟器上查看相应版本的差异。

Perhaps someone solved this problem and knows what is the reason or found its description - please share the result.也许有人解决了这个问题并且知道是什么原因或找到了它的描述 - 请分享结果。

Thanks.谢谢。

Vlad, that code works fine on my simulator and device (13.5) but I do suggest you do it differently.弗拉德,该代码在我的模拟器和设备(13.5)上运行良好,但我建议你以不同的方式进行。

It is a bit heavy handed to implement loadView and if you do you should not call super in this method.实现loadView有点笨拙,如果你这样做了,你不应该在这个方法中调用super

Why not move your code as is into viewDidLoad where you normally attach gestures?为什么不将代码原样移动到通常附加手势的viewDidLoad中? So remove loadView and do所以删除loadView并做

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

 };

You need to inspect.gestureRecognizers property in order to check what went wrong or something unusual happens.您需要检查.gestureRecognizers 属性以检查出了什么问题或发生了异常情况。

As it is a server Gesture Recognition.因为它是服务器手势识别。 you need to try shouldRecognizeSimultaneouslyWith method as written below:您需要尝试如下所示的shouldRecognizeSimultaneouslyWith方法:

gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:)

If everything goes well it'll written True.如果一切顺利,它会写成 True。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IOS:UISwipeGestureRecognizer - IOS: UISwipeGestureRecognizer UIViewPropertyAnimator 在 iOS10 和 iOS11 上反转动画的不同行为。 `isReversed` 和 `fractionComplete` 属性上的错误? - UIViewPropertyAnimator different behaviour on iOS10 and iOS11 reversing an animation. Bug on `isReversed` and `fractionComplete` properties? WhatsApp 网络客户端如何仍然使用最新的 iOS 更新(SDK 版本 13.0+)? - How does the WhatsApp web client still work with the latest iOS update (SDK version 13.0+)? iOS ShareExtension 应用程序中的数据共享问题 - Data sharing issue in iOS ShareExtension app UISwipeGestureRecognizer 在 iOS 模拟器中不起作用 - UISwipeGestureRecognizer not working in the iOS simulator ios UISwipeGestureRecognizer计算偏移量 - ios UISwipeGestureRecognizer calculate offset UISwipeGestureRecognizer在iOS 4.3中不起作用 - UISwipeGestureRecognizer not working in iOS 4.3 iOS:UISwipeGestureRecognizer的UIButton - IOS: UIButton from UISwipeGestureRecognizer UIPanGestureRecognizer 不适用于 iOS 13.0 - UIPanGestureRecognizer not working on iOS 13.0 对于最新的 iOS 版本 (12.4),不推荐使用 didUpdateLocationsTo: from: 方法。 如何用 didUpdateLocations 替换它? - didUpdateLocationsTo: from: method is deprecated for latest iOS versions(12.4). How to replace it with didUpdateLocations?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM