【问题标题】:iOS navigation bar overlapping top of UIImageView when auto resizing自动调整大小时iOS导航栏与UIImageView顶部重叠
【发布时间】:2012-11-28 13:29:42
【问题描述】:

我的 DetailView 的布局如下:

你可以看到我把 UIImageView 放在了黑色导航栏的正下方。

如果设备是纵向或横向的,我希望图像的宽度填满屏幕。

在 IB 上,UIImageView 是“Aspect Fill”并且具有 >=240 的自定义高度约束。

出现了两个问题:

  • 首先,虽然 UIImageView 的宽度填满了屏幕,但垂直尺寸不会自动调整大小

  • 其次,高度 > 240 的图像仅在导航栏下方垂直增长

有什么建议可以解决这个问题吗?如果需要,很高兴发布代码。

【问题讨论】:

    标签: iphone ios ios5 uiimageview uinavigationbar


    【解决方案1】:

    如果您不介意,我的想法是为您的 UIImageView 设置框架,而不是使用自动调整大小,如下所示

    在 - (void)viewWillAppear:(BOOL)animated

    - (void)viewWillAppear:(BOOL)animated
    {
        [self checkOrientation];
    }
    

    在检查方向

    - (void)checkOrientation
    {
        UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    
        if (UIDeviceOrientationIsLandscape(deviceOrientation)) {
            // set imageview frame to fit what you need
        }
        else if (deviceOrientation == UIDeviceOrientationPortrait) {
            // set imageview frame to fit what you need
        }
    }
    

    希望它至少对你有所帮助,谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-29
      • 1970-01-01
      • 2021-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多