zoukankan      html  css  js  c++  java
  • iOS实现ScrollView中子控件view的触摸事件响应

    实现UIScrollView子类

    #import "EgItemScrollView.h"

    @implementation EgItemScrollView

    - (instancetype)init

    {

        self = [super init];

        if (self) {

            //子控件响应触摸事件 NO表示立即响应,YES表示延迟响应

            self.delaysContentTouches = NO;

            // NO ScrollView 不处理消息由子视图处理 默认是YES

            self.canCancelContentTouches = YES;

        }

        return self;

    }

    // 当设置canCancelContentTouches=YES时,除了touchBegin以外的所有触摸事件响应前会调用

    // NO 由子视图处理消息,YES 子视图不响应消息处理

    - (BOOL)touchesShouldCancelInContentView:(UIView *)view

    {

      // myView view 自己响应消息

        if ([view isKindOfClass:NSClassFromString(@"myView")]) {

            return NO;

        }

        return [super touchesShouldCancelInContentView:view];

    }

    // 在触摸事件开始相应前调用

    // 优先于 touchesShouldCancelInContentView 判断touchBegin 默认是YES

    - (BOOL)touchesShouldBegin:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event inContentView:(UIView *)view{

        if ([view isKindOfClass:NSClassFromString(@"myView")]) {

            return YES;

        }

        return NO;

    }

     

    @end

  • 相关阅读:
    Android状态栏白底黑字,只需两步轻松搞定
    MyBatis注解
    MyBatis延迟加载和缓存
    MyBatis关联查询
    mybatis智能标签1
    Mybatis智能标签
    增删改查
    初始MyBatis
    第7章:Servlet 基础
    第3章 JSP数据交互(二)
  • 原文地址:https://www.cnblogs.com/Xujg/p/12492439.html
Copyright © 2011-2022 走看看