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

在需要给图片,图标等控件添加 点击效果,手势效果的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(@"双指双击");
    }
}

手势动作 待补充



郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。