最好的办法是停止3D触摸,而你的应用程序启动:
按照苹果的文档,你可以在这里看到:Apple Docs
用户可以关闭3D触控,而你的应用程序正在运行,因此请阅读此属性作为实施traitCollectionDidChange:委托方法的一部分。
为确保您的所有用户均可访问您的应用功能,请根据3D Touch是否可用来分支您的代码。当它可用时,利用3D Touch功能。当它不可用时,通过使用触摸和保持来提供替代方法,用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;
}
如何关闭3D触摸的代码? @Kishore Kumar – jansma
看到我的答案..,我会尝试提供更多数据 –