gpt4 book ai didi

cocoa - 自动布局,插入 View 填充容器 View

转载 作者:行者123 更新时间:2023-12-03 16:16:02 24 4
gpt4 key购买 nike

我正在尝试使插入的 View 填充它所插入的容器 View ,但是我正在获取

无效参数不满足:[constraint isKindOfClass:[NSLayoutConstraint class]]

- (void)insertedView:(NSView *)insertedView needsToFillContainerView:(NSView *)containerView {

[containerView addSubview:insertedView];
[containerView setTranslatesAutoresizingMaskIntoConstraints:NO];

[containerView addConstraints:@[
[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[insertedView]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(insertedView)],
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[insertedView]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(insertedView)]
]
];

}

基本上我想要插入的一个 View 是从 VC 加载的

最佳答案

- (void)addSubview:(NSView *)insertedView fillingAndInsertedIntoView:(NSView *)containerView {

[containerView addSubview:insertedView];
[insertedView setTranslatesAutoresizingMaskIntoConstraints:NO];

[containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[insertedView]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(insertedView)]];
[containerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[insertedView]|"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(insertedView)]];

[containeView layoutIfNeeded];
}

关于cocoa - 自动布局,插入 View 填充容器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19004758/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com