Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个带有多个子控件的 NSView。我知道我可以调用 [childControl setHidden:TRUE] 但我想知道是否可以阻止子控件的消息“drawRect:”。
我注意到不在 NSView 上调用 [super drawRect:NSZeroRect] 不会影响子控件。所以我的问题是谁调用子控件drawRect消息?如果有办法阻止它。
谢谢,何塞。
每次控件应该做出光学反应时,它们都会再次绘制它的视图。如果你真的想这样解决这个问题,你可以为每个控件创建一个子类并添加如下代码:
-(void)drawRect:(NSRect)rect { if (!self.blocked) { [super drawRect:rect]; } }
属性“blocked”是一个布尔值,如果您想阻止它,您必须将其设置为 YES 或 NO。注意:要完全隐藏它,控件子类必须在它第一次自己绘制之前被阻止。