UIScrollViews子视图在“纵向到横向"方向更改时未调整自身大小 [英] UIScrollViews subviews not resizing themselves on Portrait to Landscape Orientation Change

查看:129
本文介绍了UIScrollViews子视图在“纵向到横向"方向更改时未调整自身大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我具有诸如主视图-> UIScrollView-> UISearchBar之类的层次结构.搜索栏覆盖屏幕的整个宽度.但是,当切换到横向时,滚动视图会根据横向进行调整并覆盖整个屏幕,但其子视图(如UISearchBar宽度)与纵向保持不变.另外,我正在使用自动布局",并且已经在情节提要中正确设置了它们的约束条件(前导和尾随,宽度(大于等于320)等).

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.

我也知道在SO中有几个答案,但是几乎每个人都在willAutororate中再次说说设置宽度.但是我在UIScrollview中有大约15个子视图,我认为无法以编程方式进行设置(随着LOC的增加),而且我认为Autolayout必须对此有所解决.

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.

推荐答案

尝试一下: 此问题将通过仅约束解决.我创建了一个项目,并使用正确的约束对我来说正常工作

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

在这里,我将向您展示如何一个接一个地添加正确的约束:

  1. 仅在屏幕截图中添加滚动视图并为滚动视图添加约束:

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天全站免登陆