12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UIGestureRecognizer と UIButton メモ

Last updated at Posted at 2014-04-03

参考

http://studio.tgl.jp/blog/?p=1840
http://qiita.com/AKIHIRO_ciil/items/efb37f2aaa2136d7cca7

概要

UIGestureRecognizerとUIButton(など)を一緒に配置するとUIButtonが反応しない。
その場合、どうすればいいのか?

対応策

UIGestureRecognizerのcancelsTouchesInViewをNOにする。

header
@interface ViewController : UIViewController <UIGestureRecognizerDelegate>

- (void)viewDidLoad {
    [super viewDidLoad];

    UIGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
    gesture.cancelsTouchesInView = NO; // この設定が必要
    gesture.delegate = self;
    [self.view addGestureRecognizer:gesture];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
     if(gestureRecognizer.view == touch.view){
          return YES;
     }else{
          return NO;
     }
}
12
9
1

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
12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?