我有一个简单的UI
ImagePickerController,它将使用相机拍照,但有几件事我希望它做:
>拥有自定义相机用户界面
>采用全屏而不是480×640(如果是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]; }
我该怎么做呢?
谢谢
解决方法
对于第一个项目点,我认为您可以使用UIImagePickerController对象的cameraOverlayView属性在选择器默认界面上添加自定义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]; }