TAG

RSS订阅

收藏本站

设为首页

当前位置:主页 > 移动开发 > IOS开发 >

iOS 单击手势和双击手势共存问题

发布时间:2014-11-11 13:32 类别:IOS开发

- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 110, 200)];

    imageView.contentMode = UIViewContentModeScaleAspectFit;

    [imageView setImage:[UIImage imageNamed:@"xxx.bundle/1.jpg"]];

    imageView.userInteractionEnabled = YES;

    [self.view addSubview:imageView];

    

    UITapGestureRecognizer *singleTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap:)];

    [singleTapGestureRecognizer setNumberOfTapsRequired:1];

    [imageView addGestureRecognizer:singleTapGestureRecognizer];

    

    UITapGestureRecognizer *doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];

    [doubleTapGestureRecognizer setNumberOfTapsRequired:2];

    [imageView addGestureRecognizer:doubleTapGestureRecognizer];

    

    //这行很关键,意思是只有当没有检测到doubleTapGestureRecognizer 或者 检测doubleTapGestureRecognizer失败,singleTapGestureRecognizer才有效

    [singleTapGestureRecognizer requireGestureRecognizerToFail:doubleTapGestureRecognizer];

}

 

- (void)singleTap:(UIGestureRecognizer*)gestureRecognizer

{

    NSLog(@"-----singleTap-----");

    [self.view setBackgroundColor:[UIColor redColor]];

}

- (void)doubleTap:(UIGestureRecognizer*)gestureRecognizer

{

    [self.view setBackgroundColor:[UIColor blueColor]];

    NSLog(@"-----doubleTap-----");

}

猜你会喜欢....

Copyright © 2015 www.wahenzan.com 哇!很赞 版权所有 浙ICP备14030256号-1 Power by DedeCms

浙公网安备 33010602005986号

声明:本站所有文章除标明原创外,均来自网络转载,版权归原作者所有,如果有侵犯到您的权益,请联系本站删除 网站管理员:758763728

360网站安全检测平台