- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
self.rootVC = [[VZMConversationViewController alloc] initWithNibName:@"VZMConversationViewController" bundle:[NSBundle mainBundle]];
[self.window.contentView addSubview:self.rootVC.view];
self.rootVC.view.frame = ((NSView*)self.window.contentView).bounds;
/*
[NSLayoutConstraint constraintWithItem:self.rootVC.view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.window.contentView attribute:NSLayoutAttributeWidth multiplier:1 constant:0];
[NSLayoutConstraint constraintWithItem:self.rootVC.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.window.contentView attribute:NSLayoutAttributeHeight multiplier:1 constant:0];
//above 2 lines are not working
*/
}
嘿,我是一名试图理解mac开发的iPhone开发人员,我有上面的代码以及如何向第一个视图控制器视图添加约束,以便控制器视图通过窗口调整大小。可以在XIB中完成吗?
答案 0 :(得分:2)
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { self.rootVC = [[VZMConversationViewController alloc] initWithNibName:@"VZMConversationViewController" bundle:[NSBundle mainBundle]]; NSView *rootView=self.rootVC.view; [rootView setTranslatesAutoresizingMaskIntoConstraints:NO]; [[[self window] contentView] addSubview:rootView]; [[[self window] contentView] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[rootView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(rootView)]]; [[[self window] contentView] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[rootView]|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(rootView)]]; }
这解决了问题