控件不能与用户交互的原因
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
// 1. 圖像視圖默認(rèn)不支持用戶交互
??? self.imageView.userInteractionEnabled = NO;
??? // 2. 透明度 <= 0.01的時候,不能接受交互
//??? self.imageView.alpha = 0.02;
??? // 3. 隱藏 不能接受交互
//??? self.imageView.hidden = YES;
???
??? // 用代碼向圖像視圖添加按鈕
??? // 如果父視圖不接收用戶交互,那么其中的所有子視圖,同樣不支持用戶交互!
??? UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
??? [self.imageView addSubview:btn];
??? [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
? ??
??? // 第4種情況,如果子視圖所在位置,超出了父視圖的有效范圍,是不能交互的
??? // 即便沒有設(shè)置clipsToBounds,也只能顯示,但是不能交互!
??? // 裁剪紅色視圖,不顯示超出范圍
??? self.redView.clipsToBounds = YES;
???
??? UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
??? [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
???
??? [self.redView addSubview:btn];
轉(zhuǎn)載于:https://my.oschina.net/u/2618362/blog/665493
總結(jié)
以上是生活随笔為你收集整理的控件不能与用户交互的原因的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Table 'mysql.plugin'
- 下一篇: 杂想