我有一个简单的UIImagePickerController,它将使用相机拍照,但有几件事我希望它能做到:
这是我展示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];
}
我该怎么做?
由于
答案 0 :(得分: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
视图控制器,使用auto layout
或auto sizing
考虑设备屏幕(4英寸与否)。