iphone - UiImagePickerController takePicture 问题

标签 iphone ios ios5 uiimagepickercontroller

我在创建自己的自定义“拍照”按钮时遇到一些问题。基本上,当我删除默认控件时,相机不再执行快门动画或进行编辑过程,而是直接进入委托(delegate)方法。

所以,这是一些代码。起初我使用默认布局,如下所示:

(顺便说一句,我已经删除了用于确定硬件可用性的 if 语句 - 它们是无关紧要的。)

UIImagePickerController *picker = [[UIImagePickerController alloc] init];

picker.delegate = self;
picker.allowsEditing = YES;


picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = YES;
picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;     

[self presentModalViewController:picker animated:YES];

使用此代码,当我按下默认的“拍照”按钮时,会触发快门动画,并显示“移动和缩放” View 。按“选择”后,委托(delegate)将被调用,我可以通过 info 访问编辑结果。

这是我的新初始化代码,带有自定义“拍照”按钮,仅此而已;顺便说一下,我正在 ViewController 的 viewDidAppear 方法中初始化这个 UIImagePickerController

UIImagePickerController *picker = [[UIImagePickerController alloc] init];

picker.delegate = self;
picker.allowsEditing = YES;

UIButton *shoot = [[UIButton alloc] initWithFrame:CGRectMake(110, 420, 100, 40)];
[shoot setTitle:@"Shoot" forState:UIControlStateNormal];
[shoot.titleLabel setTextColor:[UIColor whiteColor]];
[shoot addTarget:picker action:@selector(takePicture) forControlEvents:UIControlEventTouchUpInside];

picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[picker.cameraOverlayView addSubview:shoot];
picker.showsCameraControls = NO;

picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;

[self presentModalViewController:picker animated:YES];

在此示例中,当我点击自定义按钮时,不会触发动画,不会显示编辑屏幕,会立即调用委托(delegate)。

有趣的是,如果我在上面的示例中将 showsCameraControls 属性更改为 YES,我的自定义按钮的行为方式与第一个示例中的默认按钮的行为方式完全相同.

对这个问题很困惑,我需要在 didFinishPickingMediaWithInfo 中做些什么来调用图像编辑器,还是我只是在初始化中遗漏了一些东西?

我使用的是 Xcode 4.3 和 iOS 5.1(该应用程序面向 5.0)

非常感谢任何帮助;干杯!

最佳答案

显然“移动和裁剪”功能是默认相机控件的一部分

当您使用照片库作为来源时,唯一的选项是默认选项,因此它始终有效。

最后,我使用简单的 ScrollView 和一些覆盖 View 来表示裁剪框,编写了自己的“移动和裁剪” View 。

不太难,只需根据 UIScrollView 的缩放系数和内容偏移量进行一些数学计算即可。

关于iphone - UiImagePickerController takePicture 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11440665/

相关文章:

javascript - 如何在服务器上运行 JavaScript

iphone - Flurry 中有可用的详细模式吗?

html - Apple retina 支持 HTML 中的图像

ios键盘高度不同

iphone - 关于应用内购买中的订阅问题

ios - 有没有办法检查是否堆叠了太多VC

ios - 快速返回值 URLSession.shared.dataTask

ios - 如何在使用 swift 注册后将用户的位置存储到 firebase 数据库中?

iphone - NSClassFromString() 返回一个类,即使类不可用

iphone - 获取网页图片