1
- (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 中完成吗?

4

1 回答 1

2
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    self.rootVC = [[VZMConversationViewController alloc] initWithNibName:@"VZMConversationViewController" bundle:[NSBundle mainBundle]];

    NSView *rootView=self.rootVC.view;
    [rootView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [[[自窗口] contentView] addSubview:rootView];
    [[[self window] contentView] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[rootView]|" 选项:0 指标:无视图:NSDictionaryOfVariableBindings(rootView)]];
    [[[self window] contentView] addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[rootView]|" 选项:0 指标:无视图:NSDictionaryOfVariableBindings(rootView)]];

}

这解决了问题

于 2013-07-10T14:54:00.470 回答