我在当前的touchesMoved中看到了UIViewController事件,当触摸屏在屏幕上移动时,它会画一些东西(自由绘制)。
然后在视图中添加一个subView,并将UITapGestureRecognizer(设置为numberOfTapsRequired 2)与子视图绑定,如果检测到双击,则将UIImageView移动到单击位置。当我再次尝试绘图时,会发生一些错误,绘制线现在不光滑(有些线不显示)。
由于iPhone6s和6s Plus的3D触摸,所以我无法在touchesEnded.What中检测到tapCount,对吗?
发布于 2016-01-14 13:36:25
最好的方法是在你的应用程序启动时停止3d触摸:
根据苹果文档,您可以在这里看到以下内容:苹果文档
用户可以在应用程序运行时关闭3D触摸,因此请阅读此属性,作为traitCollectionDidChange:委托方法实现的一部分。
为了确保您的所有用户都可以访问您的应用程序的功能,分支您的代码取决于是否有3D触摸可用。当它可用时,利用3D触摸功能。当它不可用时,提供替代方案,例如使用UILongPressGestureRecognizer类实现的触摸和保持。
请参考iOS人机界面指南,了解如何增强应用程序与3D触摸设备用户的交互,同时又不把其他用户抛在后面。
最佳代码:
@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;
}https://stackoverflow.com/questions/34789714
复制相似问题