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有關