我在当前touchesMoved
中有一个UIViewController
事件的视图,当触摸移动到屏幕时它将绘制一些内容(自由绘制)
然后我在视图中添加subView
并将UITapGestureRecognizer(设置numberOfTapsRequired 2)与子视图绑定,
如果检测到双击,我会将UIImageView移动到点击位置。
当我再次尝试绘制时,会发生错误,现在绘制线不平滑(某些线不显示)
由于iPhone6s和6s Plus中的3D Touch,我无法在touchesEnded
中检测到tapCount。我该怎么办?
答案 0 :(得分:0)
最佳方法是在启动应用程序时停止3D触摸:
根据Apple文档,您可以在此处看到:Apple Docs
用户可以在应用程序运行时关闭3D Touch,因此请在执行traitCollectionDidChange:delegate方法时阅读此属性。
为确保您的所有用户都可以访问您应用的功能,请根据3D Touch是否可用来分支您的代码。如果可用,请利用3D Touch功能。当它不可用时,提供替代方案,例如通过使用UILongPressGestureRecognizer类实现的触摸和保持。
请参阅iOS人机界面指南,了解如何使用支持3D Touch的设备增强应用与用户的互动,同时不让其他用户落后。
最佳代码:
@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;
}