[英]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.