6

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

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

这是我显示 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];
}

我该怎么做呢?

谢谢

4

1 回答 1

8

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

- (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)的图像:

 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;
        };
    };

编辑

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

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

之后,imageView考虑到设备屏幕(4英寸与否),使用auto layout或来满足您在视图控制器中的需要auto sizing

于 2013-04-07T17:34:58.097 回答