【问题标题】:Rotating iPhone and keeping image's proportions旋转 iPhone 并保持图像的比例
【发布时间】:2011-08-10 12:13:14
【问题描述】:

我有一个 UIScrollView,它包含 UIImageViews。所有图像都保持其图像比例 - 我的意思是,例如纵向图像高而窄,而横向图像短而宽。我在屏幕上同时有大约 4 张图像(垂直 2 张,水平 2 张),然后我可以向下滚动。

我的问题是旋转设备。我用

[self.imageScrollView setAutoresizingMask: UIViewAutoresizingFlexibleLeftMargin];// (etc)

和 imageView 相同的方法。但是图像并没有保持它们的比例。如果我设置: UIViewAutoresizingFlexibleWidth - 图像宽但高度太小 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight - 图像水平拉伸,垂直方向变小。

我需要旋转设备(纵向->横向),制作这 2 张图像(我彼此相邻)以填补空白并保持这些图像的比例。

【问题讨论】:

  • 换句话说:我想旋转设备,在 UIImageView 中旋转图片并保存它的 x:y 比例(不拉伸)。

标签: objective-c iphone uiimageview


【解决方案1】:

试试这个功能..

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        if (orientation == UIDeviceOrientationPortrait) { //Device is portait 
            //Resize the images to fit this orientation
                         image1.frame = CGRectMake(x,x,x,x);
        }
        else {
            //Device is landscape..
        }   
    return YES;
}

【讨论】:

  • 没有别的办法了吗?会有这么多的计数,这样可能会很慢.. :/
【解决方案2】:
imageView.contentMode = UIViewContentModeScaleAspectFill;

这解决了我的问题^^

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 2012-06-17
    • 2019-05-12
    • 1970-01-01
    相关资源
    最近更新 更多