簡體   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?)

我正在創建一個共享擴展,並在 iOS 13.0 及更高版本的測試期間遇到了一個奇怪的行為。 我使用UISwipeGestureRecognizer來解釋用戶在我的擴展程序主視圖上的滑動手勢。

這個簡單的代碼在下面提供了一個我想要的示例,並且可以在 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

在 iOS 13.0 和更新版本上,它什么也不記錄。 您可以在 iOS 模擬器上查看相應版本的差異。

也許有人解決了這個問題並且知道是什么原因或找到了它的描述 - 請分享結果。

謝謝。

弗拉德,該代碼在我的模擬器和設備(13.5)上運行良好,但我建議你以不同的方式進行。

實現loadView有點笨拙,如果你這樣做了,你不應該在這個方法中調用super

為什么不將代碼原樣移動到通常附加手勢的viewDidLoad中? 所以刪除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];

 };

您需要檢查.gestureRecognizers 屬性以檢查出了什么問題或發生了異常情況。

因為它是服務器手勢識別。 您需要嘗試如下所示的shouldRecognizeSimultaneouslyWith方法:

gestureRecognizer(_:shouldRecognizeSimultaneouslyWith:)

如果一切順利,它會寫成 True。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM