判斷某個控件是否顯示在主窗口的四個條件:
1恋追、是否加入主窗口
2谈截、是否隱藏
3违帆、透明度是否大于0.01
4挣磨、是不是在當(dāng)前窗口上(關(guān)鍵點根據(jù)frame判斷的時候控件的frame是不是以當(dāng)前窗口的左上角點為基準(zhǔn)判斷)
- (BOOL)isShowingOnKeyWindow
{
//主窗口
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
//以窗口的左上角為坐標(biāo)原點豪直,計算self的矩形框
CGRect newFrame = [keyWindow convertRect:self.frame fromView:self.superview];
CGRect windowBounds = keyWindow.bounds;
//判斷newFrame是不是在windowBounds上
BOOL isOnWindow = CGRectIntersectsRect(newFrame, windowBounds);
return self.window == keyWindow && !self.hidden && self.alpha > 0.01 && isOnWindow;
}