ios - 为什么 Mac Catalyst 应用程序不使用 numberOfTouchesRequired?

标签 ios uigesturerecognizer mac-catalyst

我正在使用 Mac Catalyst 将应用程序从 iOS 移植到 Mac,发现两指和三指点击手势不起作用。下面是一些示例代码:

UIView *test = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
test.backgroundColor = [UIColor redColor];
[self.view addSubview:test];
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleColumns:)];
gesture.numberOfTouchesRequired = 2;
gesture.delegate = self;
[test addGestureRecognizer:gesture];

如果我用两根手指点击我的 Magic Trackpad 上的红色框,没有任何反应。目标方法未被调用,手势委托(delegate)方法也未被调用,例如 gestureRecognizer:shouldReceiveTouch:。但是,如果我注释掉 numberOfTouchesRequired 行,那么单指点击就可以了。

我在 documentation 中没有看到任何有关此限制的信息,显然这不是多点触控的一般限制,因为 UIPinchGestureRecognizer 可以按预期工作。我是否遗漏了什么,或者我应该提交错误报告?

最佳答案

Mac Catalyst 似乎响应双指点击以显示 UIContextMenuInteraction

如果你实现了这个,你可以用它来显示一个用两根手指点击的菜单。这是一个decent tutorial .

注意:我在“缩放界面以匹配 iPad”模式下使用 mac 催化剂。

关于ios - 为什么 Mac Catalyst 应用程序不使用 numberOfTouchesRequired?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60499767/

相关文章:

ios - UIButton 颜色变化

ios - 缩放 super View 时如何防止按钮调整大小?

objective-c - 受手势影响的 UIButton

ios - UIAlertController 关闭速度很慢

ios - 在 iOS 中使用 AFNetworking 2 检查连接的最佳方法?

ios - MVC : should i add and implement touch gestures in the View Controller or my custom subclass of UIView

swiftui - 带有Big Sur的SwiftUI Catalyst中的点击问题

macos - Catalyst 转换的 Mac 应用程序中的滚轮事件捕获

ios - 为 Mac Catalyst 构建时扩展不可用

ios - 为什么我的 collectionViewCell 显示异常行为?