简体   繁体   English

约束在横向方向上未按预期工作

[英]Constraints are not working as expected in landscape orientation

I test very simple layout with autolayout use storyboard only(no code any where) 我仅使用自动布局使用故事板测试非常简单的布局(任何地方都没有代码)

i dropped the Button object wAny, hAny and then switch size class to wCompact, hAny 我放下Button对象wAny,hAny,然后将size类切换到wCompact,hAny

and add Constraint 'Center Horizontally in Container' & 'Top Space to Top layout guide'. 并添加约束“在容器中水平居中”和“顶部空间到顶部布局指南”。

next i switch size class to wAny, hCompact and add constraint 'Center Vertically in Container' & 'Trailling space to Container Margin' and width,height constraint 接下来,我将大小类切换为wAny,hCompact,并添加约束“在容器中垂直居中居中”和“在容器边距中拖尾空间”以及宽度,高度约束

that's all i added constraints, there is no warning and error in storyboard. 这就是我添加的所有限制,情节提要中没有警告和错误。

i expected as top centered button in portrait and right centered in landscape. 我期望将其设为纵向居中居中的按钮,横向居中居中。

portrait is running normally but preview and simulator show me wrong result when i was change orientation with error log. portrait正常运行,但是当我通过错误日志更改方向时,预览和模拟器向我显示了错误的结果。

like this 像这样

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "\<_UILayoutSupportConstraint:0x7a065db0 V:[_UILayoutGuide:0x7a067440(0)]>",
    "<_UILayoutSupportConstraint:0x7a068010 V:|-(0)-[_UILayoutGuide:0x7a067440]   (Names: '|':UIView:0x7a0661d0 )>",
    "<NSLayoutConstraint:0x7a0680b0 V:[_UILayoutGuide:0x7a067440]-(20)-[UIButton:0x7a066740'Button']>",
    "<NSLayoutConstraint:0x7a06d9e0 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7a0661d0(320)]>",
    "<NSLayoutConstraint:0x7a068050 UIView:0x7a0661d0.centerY == UIButton:0x7a066740'Button'.centerY>",
    "<NSLayoutConstraint:0x7a0680e0 V:[UIButton:0x7a066740'Button'(30)]>"
)

Will attempt to recover by breaking constraint "<NSLayoutConstraint:0x7a0680e0 V:[UIButton:0x7a066740'Button'(30)]>

and button fills width and height its container view. 然后按钮填充其容器视图的宽度和高度。

i can't figure out what i did wrong? 我不知道我做错了什么?

am i missing something important about autolayout(with orientation)? 我是否缺少有关自动布局(带有方向)的重要信息?

plz help me 请帮我

(sorry for my bad english. i'm non english native speaker-) (对不起,我的英语不好。我不是英语母语人士)

Your problem is that wCompact|hAny is for iPhones in portrait or landscape. 您的问题是wCompact | hAny适用于纵向或横向iPhone。 So you end up with conflicting constraints in landscape because all of your constraints apply. 因此,由于所有约束都适用,因此最终导致景观中的约束冲突。 You should use wCompact|hRegular for iPhones in portrait. 您应该为iPhone纵向使用wCompact | hRegular

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM