2016-01-14 140 views
0

我在当前UIViewController,与touchesMoved事件视图时在屏幕上触摸移动将借鉴的东西(免费抽奖)如何停止3D触摸其中断其他触摸事件?

然后我在视图中添加subView并绑定UITapGestureRecognizer(集numberOfTapsRequired 2)子视图, 如果双击被检测到,我会将UIImageView移动到点击位置。 当我再次尝试绘制时,出现了错误,画线现在不平滑(某些线不显示)

由于iPhone6s和6s Plus中的3D Touch,所以我无法检测到tapCount在touchesEnded。我该怎么办?

+0

如何关闭3D触摸的代码? @Kishore Kumar – jansma

+0

看到我的答案..,我会尝试提供更多数据 –

回答

0

最好的办法是停止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; 
    } 
+1

仍然不知道如何在应用程序运行时禁用3D Touch功能。 –

+0

@ChrisForever你面临什么问题? –

+0

@ChrisForever一步一个脚印,检查你的协议实现和所有,然后检查if和else语句是否工作。 –