简体   繁体   English

在什么时候将自动布局约束应用于视图?

[英]At what point autolayout constraints are applied to the view?

Is there any delegate or a callback to be called when autolayout constraints are added to a view and the view has been resized? 将自动布局约束添加到视图并且调整了视图的大小时,是否有任何委托或回调要调用?

In my view hierarchy ( NSStackView<--MyContainerView<--MyView ) when i add MyView, I add it to the special ContainerViewController 's view as a subview and apply constraints to it - it should fill all the area defined by ContainerViewController 's view. 在我的视图层次结构( NSStackView<--MyContainerView<--MyView )中,当我添加MyView时,我将其作为子视图添加到特殊ContainerViewController的视图中并对其施加约束-它应填充ContainerViewController定义的所有区域视图。

The code looks like this: 代码如下:

-(void)addView:(MyView*)view
{
   ContainerViewController *vc = [[ContainerViewController alloc] init];
   [vc addContentView: view]; // autolayout constraints are applied inside like "H:|[view]|" and "V:|[view]|"
   [self.stackView addView: vc.view];
}

however, after returning from addView , view's frame is still {0,0,0,0} . 但是,从addView返回后,视图的框架仍为{0,0,0,0}
How can I catch the moment when view is resized appropriately? 如何适当调整视图大小?

Not quite sure what you're after - 不确定您要做什么-

but if you want to be informed when the view's frame changes you can listen to the NSViewBoundsDidChangeNotification : 但是,如果您想在视图的框架发生更改时得到通知,则可以收听NSViewBoundsDidChangeNotification

NSView Notifications NSView通知

Make sure to read the comments about how to control the enablement of this notification. 确保阅读有关如何控制此通知的启用的注释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM