标签:uitapgesturerecogniz ios imageview app
在需要给图片,图标等控件添加 点击效果,手势效果的UITapGestureRecognizer用法
直接看代码示例:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIImageView *imgView =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0,320,100)]; imgView.backgroundColor = [UIColor redColor]; //因为没有设置image属性,为了显示出图片覆盖区域 imgView.userInteractionEnabled=YES; UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImage)]; [imgView addGestureRecognizer:singleTap]; [self.view addSubview:imgView]; }
//处理单指事件 - (void)handleSingleFingerEvent:(UITapGestureRecognizer *)sender{ if(sender.numberOfTapsRequired == 1) { //单指单击 NSLog(@"单指单击"); } else if(sender.numberOfTapsRequired == 2){ //单指双击 NSLog(@"单指双击"); } } //处理双指事件 - (void)handleDoubleFingerEvent:(UITapGestureRecognizer *)sender { if(sender.numberOfTapsRequired == 1) { //双指单击 NSLog(@"双指单击"); } else if(sender.numberOfTapsRequired == 2){ //双指双击 NSLog(@"双指双击"); } }
iOS 控件点击效果 手势效果 UITapGestureRecognizer用法
标签:uitapgesturerecogniz ios imageview app
原文地址:http://blog.csdn.net/jichunw/article/details/42914183