【问题标题】:Autolayout for Height working in iOS8 but not working in iOS7高度的自动布局在 iOS 8 中工作但在 iOS 7 中不工作
【发布时间】:2015-08-08 04:49:28
【问题描述】:

我的 UIImageView 在视图中,它将从服务器下载图像,下载完成后,我的 UIImageView 高度将根据图像的高度进行调整,但问题是它在 iOS8 中运行良好,但在 iOS7 中运行不正常。在 iOS7 中,高度缩放到比我尝试设置的要高得多。我正在通过 IB 设置自动布局

这是我的代码的摘录(默认为 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

【问题讨论】:

    标签: ios objective-c uiimageview autolayout


    【解决方案1】:

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

    尝试根据您的需要将其设置为“Aspect Fill”或“Scale to Fill”。

    【讨论】:

    • 不,事实并非如此,因为我总是在 IB 中将 contentMode 设置为 AspectFit(IF 案例在正常情况下永远不会执行)。无论如何,我已经通过在 UIImageView 和 superView 的底部之间放置更多的 NSLayoutConstrainst 解决了这个问题。这种方式锁定了大小,不会产生垂直空白
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 2013-03-03
    • 1970-01-01
    相关资源
    最近更新 更多