简体   繁体   English

iOS 7自动版式无法正常工作

[英]iOS 7 Autolayout doesn't work

I've been working today on this problem for a while now and i couldn't solve it. 我今天已经在这个问题上工作了一段时间,但无法解决。 I downloaded Apple's Autolayout Guide and couldn't find an answer/solution. 我下载了Apple的《自动排版指南》,但找不到答案/解决方案。 The problem is that I'm adding a UIImageView to my View Controller and when I change the window s form factor from 3.5 to 4 and vise versa, the image view is stretched. 问题是我将UIImageView添加到我的View Controller中,并且当我将window的尺寸系数从3.5更改为4时,反之亦然, image view被拉伸了。

To solve this, I tried many ways such as clicking on reset to suggested constraints, clear all constraints, and build my own constraints by pinning and aligning. 为了解决这个问题,我尝试了许多方法,例如,单击重置为建议的约束,清除所有约束以及通过固定和对齐来建立自己的约束。

By aligning and pinning I set the height and width to the size as in the Interface Builder and the horizontal and vertical positions as well. 通过对齐和固定,可以像在“界面生成器”中一样将heightwidth设置为大小,并在horizontalvertical位置上进行设置。 Unfortunately, the image still stretches upon changing the form factor in Interface Builder. 不幸的是,在Interface Builder中更改形状因子后,图像仍会拉伸。 I tried to only pin the height of the UIImageView but it doesn't work. 我试图只固定UIImageViewheight ,但是不起作用。

How can i work this out? 我该如何解决?

Autolayout only deals with the frame/bounds of the UIImageView . 自动布局仅处理UIImageView的框架/边界。 The actual way the image is rendered is controlled via it's contentMode property. 渲染图像的实际方式是通过它的contentMode属性控制的。 You need to set it to either UIViewContentModeScaleAspectFit or UIViewContentModeScaleAspectFill to avoid stretching. 您需要将其设置为UIViewContentModeScaleAspectFitUIViewContentModeScaleAspectFill以避免拉伸。

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

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