0
儘管隱藏超級視圖的層級,UIView的「隱藏」屬性也是「false」。即使超級視圖被隱藏,UIView隱藏屬性也是false
有沒有一種實用的方法來知道UIView是否隱藏而不爬樹?
例如:
(lldb) po 0x7ffba8120f40
<UIButtonLabel: 0x7ffba8120f40; frame = (0 6; 25 18); text = ' All'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x7ffba8121160>>
(lldb) p (BOOL)[0x7ffba8120f40 isHidden]
(BOOL) $605 = NO
(lldb) po [0x7ffba8120f40 superview]
<UIButton: 0x7ffba811ffd0; frame = (0 15; 100 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7ffba811d200>>
(lldb) p (BOOL)[0x7ffba8120f40 isHidden]
(BOOL) $607 = NO
(lldb) po [0x7ffba8120f40 superview]
<UIButton: 0x7ffba811ffd0; frame = (0 15; 100 30); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7ffba811d200>>
(lldb) p (BOOL)[0x7ffba811ffd0 isHidden]
(BOOL) $612 = NO
(lldb) po [0x7ffba811ffd0 superview]
<UIView: 0x7ffba811fe60; frame = (16 20; 110 60); autoresize = RM+BM; layer = <CALayer: 0x7ffba811d1e0>>
(lldb) p (BOOL)[0x7ffba811fe60 isHidden]
(BOOL) $614 = NO
(lldb) po [0x7ffba811fe60 superview]
<InsertViewer.ExploreHeader: 0x7ffba4de2f40; baseClass = UICollectionReusableView; frame = (-8 -20; 375 100); clipsToBounds = YES; hidden = YES; opaque = NO; layer = <CALayer: 0x7ffba811ddd0>>
(lldb) p (BOOL)[0x7ffba4de2f40 isHidden]
>>>>>>>>>>>>>>>>>>>(BOOL) $618 = YES <<<<<<<<<<<<<<<<<<<<
我更關心是否知道隱藏的祖先隱藏視圖。我訴諸檢查完整的超級視圖路徑,而不是隻測試視圖的隱藏屬性。尷尬,但工程 –
你可以用hiddenBySuperview方法創建一個UIView的擴展,如果視圖本身被隱藏,或者它的任何一個超鏈接被隱藏,它將返回TRUE。 (確保你編碼處理視圖沒有任何超級視圖的情況,在這種情況下,該方法只會返回它自己的隱藏標誌。) –