UIKit の Private な UIGestureRecognizer
UITextField
の長押し時の挙動をカスタマイズする必要があって調べてみたらいろいろと面白かった。
調べた方法は以下
UITextField
のサブクラスを作って UIView
の
- (void)addGestureRecognizer:(UIGestureRecognizer*)gestureRecognizer NS_AVAILABLE_IOS(3_2);
メソッドをオーバーライドする。
#import "MyTextField.h" @implementation MyTextField - (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { [super addGestureRecognizer:gestureRecognizer]; NSLog(@"%@", gestureRecognizer); } @end
iOS 8での出力結果は以下
<UITextTapRecognizer: 0x7faa59d3c480; state = Possible; delaysTouchesEnded = NO; view = <MyTextField 0x7faa59e1fb80>; target= <(action=oneFingerTripleTap:, target=<UITextInteractionAssistant 0x7faa59d3cf50>)>; numberOfTapsRequired = 3> <UITextTapRecognizer: 0x7faa59d3c620; state = Possible; delaysTouchesEnded = NO; view = <MyTextField 0x7faa59e1fb80>; target= <(action=oneFingerDoubleTap:, target=<UITextInteractionAssistant 0x7faa59d3cf50>)>; numberOfTapsRequired = 2> <UITextTapRecognizer: 0x7faa59d40aa0; state = Possible; delaysTouchesEnded = NO; view = <MyTextField 0x7faa59e1fb80>; target= <(action=twoFingerSingleTap:, target=<UITextInteractionAssistant 0x7faa59d3cf50>)>; numberOfTouchesRequired = 2> <UITapAndAHalfRecognizer: 0x7faa59d3fcd0; state = Possible; view = <MyTextField 0x7faa59e1fb80>; target= <(action=tapAndAHalf:, target=<UITextInteractionAssistant 0x7faa59d3cf50>)>> <UILongPressGestureRecognizer: 0x7faa59d40e20; state = Possible; delaysTouchesEnded = NO; view = <MyTextField 0x7faa59e1fb80>; target= <(action=twoFingerRangedSelectGesture:, target=<UITextInteractionAssistant 0x7faa59d3cf50>)>> <UITextTapRecognizer: 0x7faa59e2d5d0; state = Possible; delaysTouchesEnded = NO; view = <MyTextField 0x7faa59e1fb80>; target= <(action=oneFingerTap:, target=<UITextInteractionAssistant 0x7faa59d3cf50>)>> <UIVariableDelayLoupeGesture: 0x7faa59e13610; state = Possible; delaysTouchesEnded = NO; view = <MyTextField 0x7faa59e1fb80>; target= <(action=loupeGesture:, target=<UITextInteractionAssistant 0x7faa59d3cf50>)>>
1本指3回タップで発動する UITextTapRecognizer
1本指2回タップで発動する UITextTapRecognizer
2本指1回タップで発動する UITextTapRecognizer
tapAndHalf:
っていうアクションを発動する UITapAndAHalfRecognizer
2本指で長押しした時に2本の指の間のテキストを選択する UILongPressGestureRecognizer
1本指タップで発動する UITextTapRecognizer
ルーペを表示する UIVariableDelayLoupeGesture
が自動的に設定される事が分かる。