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:
の発生でジェスチャをキャンセルするような使い方をしていると全く動作しません。