0

我的 DetailView 的布局如下:

在此处输入图像描述

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

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

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

出现了两个问题:

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

  • 二、高度>240的图片只在导航栏下垂直增长

任何建议如何解决这个问题?如果需要,很高兴发布代码。

4

1 回答 1

0

如果您不介意,而不是使用自动调整大小,我的想法是为您的 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
    }
}

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

于 2012-12-13T02:25:29.490 回答