简体   繁体   English

UIImageView在横向模式下在屏幕外

[英]UIImageView off screen in landscape mode

I am using iOS7 and I have a UIViewController with a UIImageView that fill the screen in Aspect Fit mode. 我正在使用iOS7,并且有一个带有UIImageView的UIViewController,它们以Aspect Fit模式填充屏幕。 In portrait mode the image looks good but in landscape mode the image is off screen. 在纵向模式下,图像看起来不错,但是在横向模式下,图像不在屏幕上。

Can anyone help me? 谁能帮我?

Thanks ;-) 谢谢 ;-)

在此处输入图片说明

在此处输入图片说明

As you can see the image is in the same position in both orientations. 如您所见,图像在两个方向上都处于相同位置。 It's the same distance away from the top panel and pushed up against the left side of the screen. 距顶部面板的距离相同,并向上推向屏幕的左侧。 iOS doesn't automatically change the frame of the image for you when you change orientations. 更改方向时,iOS不会自动为您更改图像的框架。 You have to either do it programmatically or use auto layouts to achieve the display you want. 您必须以编程方式进行操作,或者使用自动布局来实现所需的显示。

AutoLayout Guide 自动版式指南

Autolayout is a pain to learn at first but stick with it. 一开始要学习自动排版是很痛苦的,但是坚持下去。 It's a great solution when you get the hang of constraints and start modifying them programatically. 当您掌握约束并开始以编程方式修改它们时,这是一个很好的解决方案。 In fact it's recommended you never set the frame explicitly, you should always use constraints to position and size frames. 实际上,建议您不要显式设置框架,而应始终使用约束来定位和调整框架大小。

As Literphor mentioned above. 正如上面提到的Literphor。 it is layout issue. 这是布局问题。 Either use autolayout or do the trial and error (because you are not familiar with Autosizing) with settings shown in below image. 使用下图所示的设置,或者使用自动版式或尝试一下(因为您不熟悉自动调整大小)。 That should fix the issue. 那应该解决问题。

在此处输入图片说明

self.imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin  | UIViewAutoresizingFlexibleBottomMargin |
                                  UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

You must "play" with autoresizingMask 您必须“玩” autoresizingMask

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

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