iOS button不能点击的几种情况

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不能点击和loading有关

猜你喜欢

转载自blog.csdn.net/xiaoning0905/article/details/89239909