如何使用全屏图像 ios 创建自定义 UIImagePickerController [英] How to create a custom UIImagePickerController with full-screen images ios

查看:26
本文介绍了如何使用全屏图像 ios 创建自定义 UIImagePickerController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 UIImagePickerController 将使用相机拍照,但我希望它做几件事:

I have a simple UIImagePickerController which will use the camera to take a picture, but there are a couple things I would like it to do:

  • 拥有自定义的相机界面
  • 采用全屏而不是 480x640(如果在 4 英寸手机上)

这是我显示 UIImagePickerController 的代码:

Here is my code for showing the UIImagePickerController:

- (IBAction)pick:(id)sender {
    NSLog(@"abc");
    picker = [[UIImagePickerController alloc] init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        [picker setSourceType:UIImagePickerControllerSourceTypeCamera];
    } else {
        [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    }
    [picker setDelegate:self];
    [self presentViewController:picker animated:YES completion:nil];

}

这是拍摄图像的时间:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self dismissViewControllerAnimated:YES completion:nil];
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [imageView setImage:image];
}

我该怎么做?

谢谢

推荐答案

对于第一个要点,我想您可以使用 UIImagePickerController 对象的 cameraOverlayView 属性来在选择器默认界面上添加您的自定义 UI:

For the first bullet point I suppose that you could use the cameraOverlayView property of an UIImagePickerController object to add your custom UI over the picker default interface:

- (IBAction)pick:(id)sender {
    NSLog(@"abc");
    picker = [[UIImagePickerController alloc] init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        [picker setSourceType:UIImagePickerControllerSourceTypeCamera];
    } else {
        [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    }

    // Add here your custom UI here
    [picker setCameraOverlayView:self.customCameraOverlayView];

    [picker setDelegate:self];
    [self presentViewController:picker animated:YES completion:nil];

}

编辑

我已经测试了 UIImagePickerController 并且它返回了具有完整尺寸(PixelXDimension 和 PixelYDimension)的图像:

I've tested the UIImagePickerController and it returns the image with it's full dimensions (PixelXDimension and PixelYDimension):

 UIImagePickerControllerMediaMetadata =     {
        DPIHeight = 72;
        DPIWidth = 72;
        Orientation = 6;
        "{Exif}" =         {
            ApertureValue = "2.526068811667588";
            BrightnessValue = "-0.5779073354035674";
            ColorSpace = 1;
            DateTimeDigitized = "2013:04:07 22:30:03";
            DateTimeOriginal = "2013:04:07 22:30:03";
            ExposureMode = 0;
            ExposureProgram = 2;
            ExposureTime = "0.05882352941176471";
            FNumber = "2.4";
            Flash = 24;
            FocalLenIn35mmFilm = 35;
            FocalLength = "4.28";
            ISOSpeedRatings =             (
                800
            );
            MeteringMode = 3;
            PixelXDimension = 3264;
            PixelYDimension = 2448;
            SceneType = 1;
            SensingMethod = 2;
            ShutterSpeedValue = "4.058893689053568";
            SubjectArea =             (
                1874,
                1478,
                610,
                612
            );
            WhiteBalance = 0;
        };
        "{TIFF}" =         {
            DateTime = "2013:04:07 22:30:03";
            Make = Apple;
            Model = "iPhone 4S";
            Software = "6.1.3";
            XResolution = 72;
            YResolution = 72;
        };
    };

编辑

您还可以为图像视图设置内容模式以调整大小并适合容器视图:

Also you could set to your image view the content mode to resize and fit the container view:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self dismissViewControllerAnimated:YES completion:nil];
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    [imageView setContentMode:UIViewContentModeScaleAspectFill];
    [imageView setImage:image];
}

然后根据需要在视图控制器中使用 auto layoutauto 来适应 imageView尺寸.

and after that to fit the imageView as you need in you view controller taking in consideration the device screen (4inch or not) using auto layout or auto sizing.

这篇关于如何使用全屏图像 ios 创建自定义 UIImagePickerController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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