iOS 在父视图添加手势,点击子视图,会响应父视图的手势

代码

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                                                          action:@selector(click)];
    [self.view addGestureRecognizer:tap];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 350, 400);
    button.backgroundColor = [UIColor redColor];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(kkk) forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"我是一个按钮" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:80];
    button.titleLabel.numberOfLines = 0;
    
    
    UILabel *ve = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    ve.backgroundColor = [UIColor cyanColor];
    ve.text = @"我是label1";
    ve.userInteractionEnabled =  YES;
    [self.view addSubview:ve];
    
    UILabel *ve2 = [[UILabel alloc] initWithFrame:CGRectMake(100, 500, 100, 100)];
    ve2.backgroundColor = [UIColor magentaColor];
    ve2.text = @"我是label2";
    ve2.userInteractionEnabled = YES;
    [self.view addSubview:ve2];
    // Do any additional setup aft
    // Do any additional setup after loading the view.
}

- (void)kkk
{
    NSLog(@"按钮按钮");
}

- (void)click
{
    NSLog(@"手势点击手势点击");
}
![请添加图片描述](https://img-blog.csdnimg.cn/f828973c6fec4629a1cf224d211fef60.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5YiY5YiY5bCP5Y2a,size_20,color_FFFFFF,t_70,g_se,x_16)

请添加图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值