iOS UIbutton 点击无反应的几种情况

1、UIButton不能点击情况的第一种是,你将button添加到一个不能响应点击事件的View里。如你将button添加到UIImageView中,解决办法只需将UIImageView的

userInteractionEnabled设为YES即可。

例如:

 self.headImgV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64 * Height, WWidth, 320 * Height)];

    self.headImgV.backgroundColor = [UIColor redColor];

    self.headImgV.image = [UIImage imageNamed:@"班级信息图"];

    self.headImgV.userInteractionEnabled = YES;

    [self.view addSubview:self.headImgV];


self.clearButton = [[UIButton alloc] initWithFrame:CGRectMake(0, self.headImgV.frame.size.height - 100 * Height, self.headImgV.frame.size.width, 80 * Height)];

    self.clearButton.backgroundColor = [UIColor clearColor];

    [self.clearButton addTarget:self action:@selector(clearButtonSelector:) forControlEvents:UIControlEventTouchUpInside];

    [self.headImgV addSubview:self.clearButton];

2、UIButton不能点击情况的第二种是,你对button修改frame时,出现button的frame超过了父View的frame。这种情况也会导致button点击不能触发点击事件,这种情况只需要重新就该button的frame,并让button的frame不超过父View的frame。你可以通过打印button和父View的frame来查看是否出现这种上述的这种情况。


3、UIButton不能点击情况的第三种是,你在button上添加了一个View,然后这个View能响应事件。但是这个View并没有响应的点击触发事件。所以当你在点击button的时候,是将触发事件传递给View,而button本需要触发的事件则被忽略了。解决办法是,让添加的这个View的userInteractionEnabled设为NO即可。


4,button不能点击和

SVProgressHUD 或者 MBProgressHUD有关




  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值