LoginSignup
18
18

More than 5 years have passed since last update.

注意: 3D Touch対応デバイスのみで現れるジェスチャーの挙動

Posted at

3D Touch搭載デバイスの登場によって、公開中のアプリに不具合が発生し修正が必要となったので共有します。

UIGestureRecognizerのサブクラスを作って簡単に比較します。

UIGestureRecognizerのSubclass

MyGestureRecognizer.h

#import <UIKit/UIKit.h>

@interface MyGestureRecognizer : UIGestureRecognizer

@end

MyGestureRecognizer.m

#import "MyGestureRecognizer.h"

@implementation MyGestureRecognizer

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"%s::", __PRETTY_FUNCTION__);
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"%s::", __PRETTY_FUNCTION__);
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"%s::", __PRETTY_FUNCTION__);
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"%s::", __PRETTY_FUNCTION__);
}

@end

ログの結果

0.2sほどの一瞬のシングルタップで比較します。

非3D Touch搭載デバイスのログ

-[MyGestureRecognizer touchesBegan:withEvent:]::
-[MyGestureRecognizer touchesEnded:withEvent:]::

3D Touch搭載デバイスのログ

-[MyGestureRecognizer touchesBegan:withEvent:]::
-[MyGestureRecognizer touchesMoved:withEvent:]::
-[MyGestureRecognizer touchesMoved:withEvent:]::
-[MyGestureRecognizer touchesMoved:withEvent:]::
-[MyGestureRecognizer touchesEnded:withEvent:]::

結論

非3D Touch搭載デバイスでは間に生じなかったtouchesMoved:withEvent:が、素早いシングルタップであっても3D Touch搭載デバイスでは複数回呼ばれるので注意。

touchesMoved:withEvent:の発生でジェスチャをキャンセルするような使い方をしていると全く動作しません。

18
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
18