码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 控件点击效果 手势效果 UITapGestureRecognizer用法

时间:2015-01-20 10:27:10      阅读:198      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!