UIScrollViews子视图不波泰特自己调整为横向变化 [英] UIScrollViews subviews not resizing themselves on Portait to Landscape Orientation Change

查看:144
本文介绍了UIScrollViews子视图不波泰特自己调整为横向变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我有一个主视图层次 - >的UIScrollView - >的UISearchBar。搜索栏覆盖屏幕的整个宽度。但是,当它切换为横向滚动视图根据景观调整本身并覆盖整个屏幕,但其子视图一样宽的UISearchBar保持相同的画像。再加上我使用的自动布局和我已经正确设置的约束(开头和结尾,宽度(大于等于320)​​等)的故事板。

另外,我知道有几个答案,这在左右,但几乎每个人都在willAutororate再次说设置宽度。但是我对周围的UIScrollView子视图15,我认为是不可能的编程设置(如增加LOC)加我想自动布局必须有一些解决的办法。

请指引我在这。谢谢


解决方案

试试这个:
这个问题将在限制只解决。我创建了一个项目,并通过使用正确的约束条件的及其对我工作的罚款

在这里我要告诉你如何通过一次加正确的约束条件之一:


  

      
  1. 添加滚动视图,并添加了滚动的限制只喜欢在截图:

  2.   

  2。现在添加搜索栏添加搜索栏的限制也一样,
这里下面你可以找到了滚动完整约束和搜索起来:

In my app, I have a hierarchy like Main view -> UIScrollView - > UISearchBar. The search bar covers the whole width of screen. But when it switches to landscape the scrollview adjust itself according to landscape and cover whole screen but its subviews like UISearchBar width remain same as in portrait. Plus I'm using Autolayout and I've correctly set their constraints (Leading and Trailing, width (greater than equal to 320) etc) in storyboard.

Also I know there are several answers for this in SO but almost everyone is saying set width again in willAutororate. But I have around 15 subviews in UIScrollview which I think is not possible to set programatically (as increase LOC) plus I think Autolayout must have some solution to it.

Please guide me in this. Thanks

解决方案

try this : this problem will solve by constraints only. I created a project and by using correct constraints its working fine for me ,

here I am going to show you how to add correct constraint one by one :

  1. add scrollview and add constraints for scrollview only like in the screenshots :

2. now add search bar and add constraints for search bar too, 
here below you can find out complete constraints for scrollview and search together:

这篇关于UIScrollViews子视图不波泰特自己调整为横向变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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