macOS 10.12自动布局问题 [英] macOS 10.12 auto-layout issues

查看:283
本文介绍了macOS 10.12自动布局问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

There are several huge changes in 10.12, but in my opinion the biggest is the new auto-layout system (or modified/rewritten old one ... who knows). I have prepared a simple project to demonstrate the issue. It's related with collapsing a split view item via a button. It happens only on 10.12. All you need to do is to compile the project and click the button. An error will be presented:

2016-10-04 15:10:28.284296 test-12 [64932:7425277] [布局]检测到缺少约束.无法放置它,因为没有足够的约束来完全定义大小和原点.添加缺少的约束,或设置translatesAutoresizingMaskIntoConstraints = YES,将为您生成约束.如果此视图是在macOS 10.12及更高版本上手动布置的,则可以选择不从覆盖中调用[超级布局].在DETECTED_MISSING_CONSTRAINTS上设置一个断点以进行调试.该错误只会记录一次.

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.

设置断点后,我们可以发现有问题的视图是:

After setting a breakpoint we can find out that the problematic view is:

(lldb) po $arg1
<NSSplitDividerView: 0x618000161980>

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

Am I completely wrong or there is a definite problem with 10.12? And please advice how to prevent such type of errors if possible.

可以从 github

再次感谢您的帮助.

I.尼科洛夫

推荐答案

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

I have the same auto-layout issue and I found a workaround for my project. After adding the subview with its constrains I call the window to "layout". Unfortunately I do that after each "add" call, otherwise the system will throw the ugly message again. It works for me and I am just calling it during initialistion.

  // 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 10.12自动布局问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆