简体   繁体   English

设备轮换时iOS无法自动调整子视图

[英]iOS unable to autoresize subviews when device rotation

I tried several solutions found on other posts but still having problems to autoresize subviews when device rotation. 我尝试了在其他帖子上找到的几个解决方案,但在设备轮换时仍然存在自动调整子视图的问题。 My layout (IB) has three views and only apply resize to current view. 我的布局(IB)有三个视图,仅将大小调整应用于当前视图。 If then, after rotating device, view is shown, was not resized and remains at previous dimensions. 如果那时,在旋转设备后,显示视图,未调整大小并保持在先前的尺寸。 I set autoresize subviews and its mask... What am I doing wrong or missing? 我设置了autoresize子视图及其面具......我做错了什么或丢失了什么? any help would be appreciated, thank you! 任何帮助将不胜感激,谢谢!

- (void)viewDidLoad
{

    [super viewDidLoad];

    [self.view setAutoresizesSubviews:YES];
    [self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
    [vistaSocial setAutoresizesSubviews:YES];
    [vistaSocial setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
    [vistaB setAutoresizesSubviews:YES];
    [vistaB setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];

I think you are not using a proper resizing properties on xib file. 我认为你没有在xib文件上使用适当的大小调整属性。 As per my understanding, you must have added 2-3 views on current controller; 根据我的理解,您必须在当前控制器上添加2-3个视图; but auto-resizing is getting wrong somewhere. 但是自动调整大小在某个地方出错了。 Try one by one and with a correct set. 逐个尝试并使用正确的设置。 You can share any screen shot for better understanding, if i am predicting it wrong. 如果我预测它错了,你可以分享任何屏​​幕截图以便更好地理解。

You can set Autoresize property with the help of Nib file. 您可以在Nib文件的帮助下设置Autoresize属性。 Can you please check once you set it properly from NIB file? 从NIB文件中正确设置后,可以检查一下吗?

For a given view to adjust its size upon device rotation, it is its superview that needs to have its autoresizesSubviews property set to YES . 对于给定视图在设备旋转时调整其大小,它的autoresizesSubviews需要将其autoresizesSubviews属性设置为YES (It is not clear from your code fragment what your view hierarchy is.) Try changing (从您的代码片段中不清楚您的视图层次结构是什么。)尝试更改

[vistaB setAutoresizesSubviews:YES];

to

[vistaB.superview setAutoresizesSubviews:YES];

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

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