自动布局保持拉伸UIImageView [英] Auto Layout keeps stretching UIImageView
问题描述
我正在使用自动布局,这让我发疯了。我已尽我所能阻止UIImageView全面展开。我不知道为什么会那样做。我尝试使用约束,解决自动布局问题。目前,唯一的解决方案是转动自动布局本身。
I am using Auto layout and it's driving me crazy. I have done everything I could to prevent UIImageView from stretching all over. I have no idea why it does that. I tried using constraints, solving auto layout issues. For now, the only solution was turning the auto layout itself.
有谁能告诉我为什么xcode完全忽略了我的约束?当我明确地设置它时,我希望UIImage保持为320x320,但是noooooooo ....
Could anyone please tell me why xcode is completely ignoring my constraints? I would expect the UIImage to stay as 320x320 when I explicitly set it as that, but noooooooo....
我想发布图片,但网站不会让我,我想为这个问题添加代码,以便它更具体,但实际上根本没有代码。我只是从故事板中拖出UIImageView,把它缩小,按原样设置约束,它只是忽略了我的代码。
I want to post images, but the site won't let me, and I would like to add code to this question so that it is more specific, but there's literally no code at all. I just dragged "UIImageView" from storyboard, made it small, set constraints as is, and it's just ignoring my code.
推荐答案
您需要确保将 UIImageView
设置为剪切到边界。如果没有,图像将溢出视图并且看起来不会正确拉伸(即使实际上是这样)。
You'll want to make sure your UIImageView
is set to clip to bounds. If not, the image will spill out of the view and will appear to not stretch correctly (even though in reality it is).
在界面构建器中,确保剪辑选中子视图框。
In interface builder, make sure the Clip Subviews box is checked.
如果您没有使用界面构建器,以下代码将执行相同的操作:
If you're not using interface builder, the following code will do the same thing:
yourImageView.clipsToBounds = YES;
这篇关于自动布局保持拉伸UIImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!