自动布局的高度在iOS8上工作,但在iOS7不工作 [英] Autolayout for Height working in iOS8 but not working in iOS7

查看:120
本文介绍了自动布局的高度在iOS8上工作,但在iOS7不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我在,将从服务器和下载完成,然后我的UIImageView高度后下载图像视图的UIImageView会根据图像的高度进行调整,但问题是它在iOS8上而不是在iOS7可以正常使用。在iOS7,该高度被缩放到比我试图设置更多。我通过IB设置自动布局

下面是我的code中的摘录(默认为250)

 如果(image.size.height< 250)headerView.itemImageView.contentMode = UIViewContentModeCenter;
                 其他{
                   adjustedHeight = image.size.height * 320.0f / image.size.width;
                     imageHeight = adjustedHeight;                     [headerView.heightContraintLayout setConstant:adjustedHeight];
                [headerView.itemImageView layoutIfNeeded]
 后//这行code的,我检查itemImageView的尺寸扩大比我在previous线设置(这只是发生在iOS7不iOS8上的adjestedHeight更多


解决方案

您设置图像视图的内容模式为中心。

尝试设置为看点填充,或根据需要达到什么样的缩放以填充。

I have my UIImageView in the view which will download image from server and after downloading finish then my UIImageView height will be adjusted according to height of image but the problem is it is working perfectly in iOS8 but not in iOS7. In iOS7, the height is scaled to much more than I tried to set. I am setting autolayout via IB

Here is the excerpt from my code (default is 250)

 if(image.size.height<250) headerView.itemImageView.contentMode =      UIViewContentModeCenter;
                 else{


                   adjustedHeight =      image.size.height*320.0f/image.size.width;


                     imageHeight = adjustedHeight;

                     [headerView.heightContraintLayout setConstant:adjustedHeight];
                [headerView.itemImageView layoutIfNeeded];
 //after this line of code, I check the size of itemImageView is extended more than the adjestedHeight that I set in the previous line ( this only happened in iOS7 not iOS8

解决方案

You set the image view's content mode to "centre".

Try setting it to "Aspect Fill" or "Scale to Fill" according to what you need to achieve.

这篇关于自动布局的高度在iOS8上工作,但在iOS7不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆