gpt4 book ai didi

macos-sierra - macOS 10.12自动布局问题

转载 作者:行者123 更新时间:2023-12-04 04:40:30 24 4
gpt4 key购买 nike

10.12中有几个巨大的变化,但我认为最大的变化是新的自动版式系统(或修改/重写的旧版式...谁知道)。我准备了一个简单的项目来演示该问题。这与通过按钮折叠拆分 View 项有关。它仅在10.12上发生。您需要做的就是编译项目,然后单击按钮。将出现错误:

2016-10-04 15:10:28.284296 test-12[64932:7425277] [Layout] Detected missing constraints for . It cannot be placed because there are not enough constraints to fully define the size and origin. Add the missing constraints, or set translatesAutoresizingMaskIntoConstraints=YES and constraints will be generated for you. If this view is laid out manually on macOS 10.12 and later, you may choose to not call [super layout] from your override. Set a breakpoint on DETECTED_MISSING_CONSTRAINTS to debug. This error will only be logged once.



设置断点后,我们可以发现问题 View 是:
(lldb) po $arg1
<NSSplitDividerView: 0x618000161980>

我是完全错误的还是10.12确实存在问题?并请提出建议,如果可能的话,如何防止此类错误。

可以从 github下载该项目

再次感谢您的帮助。

尼科洛夫(I. Nikolov)

最佳答案

我有同样的自动版式问题,并且找到了针对我的项目的解决方法。
在添加带有约束的 subview 之后,我将窗口称为“布局”。不幸的是,我在每次“添加”调用之后都这样做,否则系统将再次抛出难看的消息。它对我有用,我只是在初始化时就称呼它。

  // Left Split View
[self.scrollviewMain setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.viewMainLeft addSubview:self.scrollviewMain];
[self.viewMainLeft addConstraint:[NSLayoutConstraint constraintWithItem:self.viewMainLeft attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.scrollviewMain attribute:NSLayoutAttributeBottom multiplier:1.0 constant:l_floatConstant]];
[self.viewMainLeft addConstraint:[NSLayoutConstraint constraintWithItem:self.viewMainLeft attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.scrollviewMain attribute:NSLayoutAttributeTop multiplier:1.0 constant:-l_floatConstant]];
[self.viewMainLeft addConstraint:[NSLayoutConstraint constraintWithItem:self.viewMainLeft attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.scrollviewMain attribute:NSLayoutAttributeLeft multiplier:1.0 constant:-l_floatConstant]];
[self.viewMainLeft addConstraint:[NSLayoutConstraint constraintWithItem:self.viewMainLeft attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.scrollviewMain attribute:NSLayoutAttributeRight multiplier:1.0 constant:l_floatConstant]];
[self.windowMain layoutIfNeeded];
// Right Split View
[self.scrollviewDetails setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.viewMainRight addSubview:self.scrollviewDetails];
[self.viewMainRight addConstraint:[NSLayoutConstraint constraintWithItem:self.viewMainRight attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.scrollviewDetails attribute:NSLayoutAttributeBottom multiplier:1.0 constant:l_floatConstant]];
[self.viewMainRight addConstraint:[NSLayoutConstraint constraintWithItem:self.viewMainRight attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.scrollviewDetails attribute:NSLayoutAttributeTop multiplier:1.0 constant:-l_floatConstant-1]];
[self.viewMainRight addConstraint:[NSLayoutConstraint constraintWithItem:self.viewMainRight attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.scrollviewDetails attribute:NSLayoutAttributeLeft multiplier:1.0 constant:-l_floatConstant]];
[self.viewMainRight addConstraint:[NSLayoutConstraint constraintWithItem:self.viewMainRight attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.scrollviewDetails attribute:NSLayoutAttributeRight multiplier:1.0 constant:l_floatConstant]];
[self.windowMain layoutIfNeeded];

关于macos-sierra - macOS 10.12自动布局问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39852109/

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