How to create a custom UIImagePickerController with full-screen images ios(如何使用全屏图像 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 layout
或 auto 来适应
.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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用全屏图像 ios 创建自定义 UIImagePickerController
基础教程推荐
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01