ios 二次点击不适用于与MacCatalyst移植的iPadOS

ss2ws0br  于 2023-05-19  发布在  iOS
关注(0)|答案(1)|浏览(152)

我正试图用Catalyst将iPadOS应用程序带到macOS上。该应用程序支持iPadOS 13.4发布的指针(鼠标/触控板)交互。应用程序中有一些手势可以通过辅助指针点击来工作,但在催化剂版本中,它们似乎不起作用。似乎没有手势识别器或视图接收由二次点击发起的事件。我也试过一个干净的应用程序,结果是一样的。
在调查这个问题时,我用我的自定义实现覆盖了UIApplication,以通过sendEvent(_:)捕获所有事件,在调试时,我确认事件被传递,至少到那一点,但随后没有UIGestureRestureRecognizerUIView接收到这些事件。

sqxo8psd

sqxo8psd1#

二次点击事件可以在UIApplicationsendEvent:中拦截。默认的实现似乎正在过滤掉它们。下面是一个将它们转发到ViewController的示例实现:

- (void)sendEvent:(UIEvent *)event
{
    if (@available(macCatalyst 13.4, iOS 13.4, *)) {
        if (event.type == UIEventTypeTouches) {
            ViewController *vc = (ViewController *)self.delegate.window.rootViewController;
            NSSet<UITouch *> *touches = [event touchesForView:vc.view];
                
            NSMutableSet<UITouch *> *began = [NSMutableSet new];
            NSMutableSet<UITouch *> *moved = [NSMutableSet new];
            NSMutableSet<UITouch *> *ended = [NSMutableSet new];
            NSMutableSet<UITouch *> *cancelled = [NSMutableSet new];
            
            for (UITouch *touch in touches) {
                if (event.buttonMask == 2 && touch.phase == UITouchPhaseBegan) {
                    [began addObject:touch];
                    [secondaryTouches addObject:touch];
                }
                
                if (event.buttonMask == 2 && touch.phase == UITouchPhaseMoved) {
                    [moved addObject:touch];
                }
                
                if (touch.phase == UITouchPhaseEnded && [secondaryTouches containsObject:touch]) {
                    [ended addObject:touch];
                    [secondaryTouches removeObject:touch];
                }
                
                if (touch.phase == UITouchPhaseCancelled && [secondaryTouches containsObject:touch]) {
                    [cancelled addObject:touch];
                    [secondaryTouches removeObject:touch];
                }
            }
            
            if ([began count])
                [vc touchesBegan:began withEvent:event];
            if ([moved count])
                [vc touchesMoved:moved withEvent:event];
            if ([ended count])
                [vc touchesEnded:ended withEvent:event];
            if ([cancelled count])
                [vc touchesCancelled:cancelled withEvent:event];
        }
    }
    [super sendEvent:event];
}

相关问题