zoukankan      html  css  js  c++  java
  • 解决UIScrollView 的点击事件

    目前有两种方法

    第一种 通过 Category 扩展 UIScrollView 对象,添加触摸事件,(不建议,后续扩展不方便)代码如下

    @implementation UIScrollView (ExtendTouch)
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        [[self nextResponder] touchesBegan:touches withEvent:event];
        [super touchesBegan:touches withEvent:event];
        UITouch *touch = [touches anyObject];
        CGFloat startx = [touch locationInView:self].x;
        NSLog(@"%f",startx);
    }
    
    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        [[self nextResponder] touchesMoved:touches withEvent:event];
        [super touchesMoved:touches withEvent:event];
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        [[self nextResponder] touchesEnded:touches withEvent:event];
        [super touchesEnded:touches withEvent:event];
    }
    

     第二种 添加手势 (推荐,易于维护)

        
        //添加点按击手势监听器
        UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapUiscrollView:)];
        //设置手势属性
        tapGesture.delegate = self;
        tapGesture.numberOfTapsRequired=1;//设置点按次数,默认为1,注意在iOS中很少用双击操作
        tapGesture.numberOfTouchesRequired=1;//点按的手指数
        [self.scrllview addGestureRecognizer:tapGesture];
    

      

    @interface ViewController ()<UIScrollViewDelegate,UIGestureRecognizerDelegate>
    

      

  • 相关阅读:
    通信信号处理的一些基本常识
    欧拉公式
    css3圆角讲解
    css3投影讲解、投影
    css3变形讲解
    浏览器兼容问题
    css3渐变详解
    css中em与px
    복 경 에 갑 니 다 去北京
    我在北京:)
  • 原文地址:https://www.cnblogs.com/ak23173969/p/4450644.html
Copyright © 2011-2022 走看看