即使隐藏了超级视图,UIView隐藏属性也是假的

时间:2016-09-18 12:24:32

标签: ios objective-c uiview calayer

UIView的“隐藏”属性是“假”,即使在超级视图上隐藏了超级视图。

是否有一种实用的方法可以知道在没有攀爬树的情况下是否隐藏了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 <<<<<<<<<<<<<<<<<<<<

1 个答案:

答案 0 :(得分:0)

每个子视图都有自己的隐藏属性。如果父视图将其隐藏属性设置为true,并且其中一些子视图也标记为隐藏,则当您将父隐藏标志更改为FALSE时,父级和它的非隐藏子级将变为可见但隐藏的子级将不会显示

我不知道一种方法可以判断一个子视图是否真的是非隐藏的,而没有走上超级视图树,检查所有父视图的隐藏状态。即使这样也不能保证它是可见的,因为它可以被父母的边界剪切,或者它可以有一个遮罩层,或者它的不透明度可能是零,或者可能还有其他一些东西。