首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何停止3d触摸其中断其他触摸事件?

如何停止3d触摸其中断其他触摸事件?
EN

Stack Overflow用户
提问于 2016-01-14 12:32:00
回答 1查看 929关注 0票数 1

我在当前的touchesMoved中看到了UIViewController事件,当触摸屏在屏幕上移动时,它会画一些东西(自由绘制)。

然后在视图中添加一个subView,并将UITapGestureRecognizer(设置为numberOfTapsRequired 2)与子视图绑定,如果检测到双击,则将UIImageView移动到单击位置。当我再次尝试绘图时,会发生一些错误,绘制线现在不光滑(有些线不显示)。

由于iPhone6s和6s Plus的3D触摸,所以我无法在touchesEnded.What中检测到tapCount,对吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-14 13:36:25

最好的方法是在你的应用程序启动时停止3d触摸:

根据苹果文档,您可以在这里看到以下内容:苹果文档

用户可以在应用程序运行时关闭3D触摸,因此请阅读此属性,作为traitCollectionDidChange:委托方法实现的一部分。

为了确保您的所有用户都可以访问您的应用程序的功能,分支您的代码取决于是否有3D触摸可用。当它可用时,利用3D触摸功能。当它不可用时,提供替代方案,例如使用UILongPressGestureRecognizer类实现的触摸和保持。

请参考iOS人机界面指南,了解如何增强应用程序与3D触摸设备用户的交互,同时又不把其他用户抛在后面。

最佳代码:

代码语言:javascript
运行
复制
@interface ViewController () <UIViewControllerPreviewingDelegate>
@property (nonatomic, strong) UILongPressGestureRecognizer *longPress;
For backward compatibility I’ll also add a long press gesture recogniser here. Should our sample app be run on a device without 3D Touch support, at least the preview can be brought up via a long press gesture.

We’ll check if 3D Touch is available using something like the following method. To complete the setup, I’ve also included a custom initialiser for the long press gesture.

    - (void)check3DTouch {

        // register for 3D Touch (if available)
        if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {

            [self registerForPreviewingWithDelegate:(id)self sourceView:self.view];
            NSLog(@"3D Touch is available! Hurra!");

            // no need for our alternative anymore
            self.longPress.enabled = NO;

        } else {

            NSLog(@"3D Touch is not available on this device. Sniff!");

            // handle a 3D Touch alternative (long gesture recognizer)
            self.longPress.enabled = YES;

            }
    }

    - (UILongPressGestureRecognizer *)longPress {

        if (!_longPress) {
            _longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(showPeek)];
            [self.view addGestureRecognizer:_longPress];
        }
        return _longPress;
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34789714

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档