全屏UIImageView中的横向模式图像 [英] landscape mode images in a full screen UIImageView

查看:301
本文介绍了全屏UIImageView中的横向模式图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以让UIImageView处理横向图像与纵向图像的方式有所不同?

Is it possible to let the UIImageView handle landscape images differently from portrait images?

我将尝试解释,我有ImageViewControllerUIImageView,它们可以填满整个屏幕.
用户有时会启动UIImagePickerController并从相机胶卷中选择图片.
然后,我用该图片创建ImageViewController的实例并将其推送

I'll try to explain, I have ImageViewController with a UIImageView that fill the entire screen.
In some point the user launch a UIImagePickerController and choose a picture from the camera roll.
Then I create an instance of the ImageViewController with that picture and push it

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];


    ImageViewController *ivc = [[ImageViewController alloc] initWithImage:image];
    [picker pushViewController:ivc animated:YES];
    [ivc release];
}

问题是,如果图像处于横向模式,它仍然会填满整个屏幕.
我希望它看起来像iPhone照片应用程序如何呈现风景图像(在屏幕中央有黑色背景).

The problem is, if the image is in landscape mode, it still fill the entire screen.
I want it to look like how the iPhone photos app present a landscape image (in the center of the screen with a black background).

是否有一种在UIImageView中显示横向模式图像的方式?还是需要根据图像方向设置imageView框架?

Is there a build in way to show landscape mode images in UIImageView? or do I need to set the imageView frame according to the image orientation?

推荐答案

只需设置以下内容:

imageView.contentMode = UIViewContentModeAspectFit;

它将保持比例适应屏幕,而不是填充屏幕.

And it will keep the proportion and fit the screen, not filling it.

这篇关于全屏UIImageView中的横向模式图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆