简体   繁体   English

iOS-自动版面轮换无法正常运作

[英]iOS - auto layout rotation not working as expected

I have app with enabled rotation for iPad (iPhone version is rotation-free). 我有为iPad启用旋转功能的应用程序(iPhone版本没有旋转功能)。 In my design, within storyboard, I have this hierarchy: UIView - UIScrollView - UIView . 在我的设计中,在情节提要中,我具有以下层次结构: UIView - UIScrollView - UIView All "views" are set to have full width of the screen. 所有“视图”均设置为全屏显示。 Second UIView has class set to MyView , which is a class with an external xib file. 第二个UIView类设置为MyView ,这是一个带有外部xib文件的类。 Storyboard and xib are both created in a portrait mode. 情节提要和xib均以纵向模式创建。

Now for the problem. 现在解决问题。

  • If I run the app in the landscape mode, all is loaded OK. 如果我在横向模式下运行该应用程序,则一切加载正常。 If I rotate app after that, all is OK. 如果此后我旋转应用程序,一切正常。

  • If I run the app in the portrait mode, the design "breaks". 如果我以纵向模式运行该应用程序,则设计会“中断”。 The entire content is thiner (so there is about 100+ px gap between the end of MyView and the end of the screen). 整个内容较薄(因此MyView的末尾与屏幕的末尾之间有大约100+ px的间隙)。 If I rotate app, the design remains broken but correctly "enlarged". 如果我旋转应用程序,则设计仍然会损坏,但会正确地“放大”。 The gap is still of the same size. 间隙仍然是相同的大小。 During the first launch, I got the following error in debugger: 在第一次启动期间,我在调试器中收到以下错误:

     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) ( "<NSAutoresizingMaskLayoutConstraint:0x1545b7800 h=-&- v=-&- UIView:0x1546a8cb0.width == ScrollableContentView:0x154575da0.width - 232>", "<NSLayoutConstraint:0x15458dd80 H:[UIActivityIndicatorView:0x1546afa60]-(370)-| (Names: '|':UIView:0x1546ab840 )>", "<NSLayoutConstraint:0x15458ddd0 H:|-(361)-[UIActivityIndicatorView:0x1546afa60] (Names: '|':UIView:0x1546ab840 )>", "<NSLayoutConstraint:0x1546c7080 H:[UIView:0x1546ab840]-(0)-| (Names: '|':UIView:0x1546a8cb0 )>", "<NSLayoutConstraint:0x1546c7120 H:|-(0)-[UIView:0x1546ab840] (Names: '|':UIView:0x1546a8cb0 )>", "<NSLayoutConstraint:0x154579710 H:|-(0)-[ScrollableContentView:0x154575da0] (Names: '|':UIScrollView:0x15504c000 )>", "<NSLayoutConstraint:0x154686ef0 UIScrollView:0x15504c000.centerX == ScrollableContentView:0x154575da0.centerX>", "<NSLayoutConstraint:0x154697cc0 H:[UIScrollView:0x15504c000]-(0)-| (Names: '|':UIView:0x154547b80 )>", "<NSLayoutConstraint:0x154697d10 H:|-(0)-[UIScrollView:0x15504c000] (Names: '|':UIView:0x154547b80 )>", "<NSLayoutConstraint:0x15463b8c0 'UIView-Encapsulated-Layout-Width' H:[UIView:0x154547b80(768)]>" ) Will attempt to recover by breaking constraint 

No matter what I do, I am unable to remove this problem. 无论我做什么,我都无法消除此问题。 Even If I deleted almost every constraint I have still the same issue. 即使删除了几乎所有约束,我仍然遇到相同的问题。

You should look if you don't have any auto layout warnings in your storyboard or xib file (yellow/red dot beside your controller name in document outline). 您应该查看故事板或xib文件中是否没有任何自动布局警告(文档轮廓中控制器名称旁边的黄色/红色圆点)。

If you don't have any, do you set your constraints when adding your xib view ? 如果没有,在添加xib视图时是否设置约束?

Have you think about content hugging priority or content compression resistance priority ? 您是否考虑过content hugging prioritycontent compression resistance priority

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

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