zoukankan      html  css  js  c++  java
  • iOS 事件穿透

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

        

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

        btn.frame = CGRectMake(80, 100, 100, 50);

        btn.backgroundColor = [UIColor redColor];

        [btn setTitle:@"click me" forState:UIControlStateNormal];

        [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:btn];

        

        MyView1 *view = [[MyView1 alloc] initWithTestFrame:CGRectMake(100, 100, 200, 200)];

        [self.view addSubview:view];

    }

    // ---------------------------------------------自定义VIEW

    #import "MyView1.h"

    @implementation MyView1

    /*

    // Only override drawRect: if you perform custom drawing.

    // An empty implementation adversely affects performance during animation.

    - (void)drawRect:(CGRect)rect {

        // Drawing code

    }

    */

    UIButton *btn;

    -(id)initWithTestFrame:(CGRect) frame

    {

        self = [super initWithFrame:frame];

        if(self)

        {

            

            self.backgroundColor = [UIColor blueColor];

            [self drawView];

            

    //        self.userInteractionEnabled = NO;

        }

        return self;

    }

    -(void) drawView

    {

        

        btn = [UIButton buttonWithType:UIButtonTypeCustom];

        btn.frame = CGRectMake(0, 0, 50, 30);

        btn.backgroundColor = [UIColor blackColor];

        [btn setTitle:@"btn" forState:UIControlStateNormal];

        [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];

        [self addSubview:btn];

    }

    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

    {

        

        CGRect rect = btn.frame;

        BOOL containsPoint = CGRectContainsPoint(rect, point);

        if(containsPoint)

        {

            self.userInteractionEnabled = YES;

        }

        else

        {

            self.userInteractionEnabled = NO;

        }

        

        UIView *touchedView = [super hitTest:point withEvent:event];

        

        return touchedView;

    }

    -(void)click

    {

        NSLog(@"black...");

    }

    @end

  • 相关阅读:
    js 操作文件
    Thymeleaf在js中使用表达式
    JUnit5常用注解
    .Net开发步骤
    springboot自定义 HandlerMapping
    期末加分+总结
    SAP ABAP 性能优化技巧 – 修改一组纪录
    SAP ABAP 性能优化技巧 – 视图取代基本表
    Sql Server 日期格式化函数 (转)
    SAP ABAP 性能优化技巧 — 使用二分查找(Binary Search)选项
  • 原文地址:https://www.cnblogs.com/xiangjune/p/4883080.html
Copyright © 2011-2022 走看看