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>
    

      

  • 相关阅读:
    【转载】分布式之redis复习精讲
    Oracle学习笔记——常用函数总结
    数据库 字段动态添加
    c# form的设定
    C# 单元测试,测试资源管理器里面没有需要的单元测试
    Nvidia--cuda--document
    C# 文件的读取与另存为(WPF)
    java反射概述
    java设计模式:工厂模式
    oracle表被锁定的解决办法
  • 原文地址:https://www.cnblogs.com/ak23173969/p/4450644.html
Copyright © 2011-2022 走看看