Copyright (C) iPhoneアプリ開発備忘録 All rights reserved.
ブログ内で記したコード、内容の正確性は保証いたしません。
記載内容を実装したことにより発生した不具合・損害等の責任は一切負いません。



2013年10月22日

UILongPressGestureRecognizer が動作しない場合のチェックポイント



UILongPressGestureRecognizer(ロングプレスジェスチャー)が機能しない場合は、下記の3点をチェックする。

1. ヘッダファイルに、UIGestureRecognizerDelegate を定義していること。
@interface ViewController : UIViewController< UIGestureRecognizerDelegate >


2. delegate に selfを設定していること。
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)];
longPressGesture.allowableMovement = 5.0; // 指のズレを許容する範囲 5px
longPressGesture.minimumPressDuration = 2.0; // イベントが発生するまでタップする時間(秒)
longPressGesture.numberOfTapsRequired = 0; // タップする回数 1回の場合は[0] 2回の場合は[1]を指定
longPressGesture.numberOfTouchesRequired = 1; // タップする指の数
longPressGesture.delegate = self;
[self.view addGestureRecognizer:longPressGesture];


3. shouldRecognizeSimultaneouslyWithGestureRecognizer メソッドの戻り値に、YESを設定していること。
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
return YES;
}



参考記事:
http://stackoverflow.com/questions/14686406/uilongpressgesturerecognizer-not-working
タグ:IOS Mac apple iPAD iPhone
posted by mobileDeveloper at 23:57 | Comment(0) | TrackBack(0) | UILongPressGestureRecognizer はてなブックマーク - UILongPressGestureRecognizer が動作しない場合のチェックポイント | このブログの読者になる | 更新情報をチェックする
この記事へのコメント
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント:

認証コード: [必須入力]


※画像の中の文字を半角で入力してください。
※ブログオーナーが承認したコメントのみ表示されます。

この記事へのトラックバック
Apple、Appleのロゴ、App Store、iPodのロゴ、iTunesは、米国および他国のApple Inc.の登録商標です。
iPhone、iPod touch、iPadはApple Inc.の商標です。
iPhone商標は、アイホン株式会社のライセンスに基づき使用されています。
その他、本ブログに記載されている製品名、会社名は、それぞれ各社の商標または登録商標です。