【问题标题】:uiimageview aspectfit questionuiimageview aspectfit 问题
【发布时间】:2011-05-05 08:49:42
【问题描述】:

我使用图像选择器从我的照片库中选择图像,然后在 uiimageview 中显示该图像。风景照片效果很好,但肖像图像有些奇怪。肖像图像应该填满左右空白,但事实并非如此。

无法弄清楚为什么图片不会填满左右空间,因为 imageview 框架确实指定了 mainScreen 边界。

如果我去掉 aspectfit,那么 potrait 图像会很好地显示,但风景图像会被拉伸以填满整个 imageview。

我的代码如下:

CGRect frame = [[UIScreen mainScreen] bounds];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame];

UIImageView *selectedImageView = [[UIImageView alloc] initWithFrame:frame];
selectedImageView.image = image;

selectedImageView.contentMode = UIViewContentModeScaleAspectFit;

[scrollView addSubview:selectedImageView];
[selectedImageView release];

scrollView.delegate = self;

[self.view addSubview:scrollView];
[scrollView release];

这是它的样子:

编辑:我的目标是像显示在相册中一样显示照片,开始时适合视图并允许放大到某个限制。

【问题讨论】:

    标签: iphone uiimageview uiimagepickercontroller


    【解决方案1】:

    试试

    UIImageView *logoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo_bg.png"]];
    [logoImageView setFrame:CGRectMake(0, 0, 320, [UIImage imageNamed:@"logo_bg.png"].size.height)];
    [mainView addSubview:logoImageView];
    

    【讨论】:

    • 没有工作,因为我的图像很大,框架高度太大。
    • 在这种情况下,将滚动视图 scrollView.contentSize 设置为图像大小,将滚动视图框架设置为您需要显示的矩形大小
    猜你喜欢
    • 2017-09-13
    • 2010-11-30
    • 2011-10-07
    • 2015-05-03
    • 2011-05-31
    • 2011-02-02
    • 2011-05-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多