UiImagePickerController takePicture问题 [英] UiImagePickerController takePicture issues
问题描述
我在创建自己的自定义拍照按钮时遇到了一些问题。基本上,当我删除默认控件时,相机不再进行快门动画或完成编辑过程,只需直接进行委托方法。
I am having some issues creating my own custom "Take Picture" button. Basically, when I remove the default controls, the camera no longer does a shutter animation or goes through the editing process, just goes straight to the delegate method.
所以,这里是一些代码。起初我使用的是默认布局,如下所示:
So, here's some code. At first I was using the default layout, like so:
(顺便说一句,我删除了用于确定硬件可用性的if语句 - 它们无关紧要。)
(by the way, I've removed my if statements for determining hardware availability - they're irrelevant.)
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];
使用此代码,当我按下默认的拍照按钮时,会关闭快门动画,并显示移动和缩放视图。按下选择后,代表被调用,我可以通过 info
访问编辑结果。
With this code, when I press the default "take photo" button, the shutter animation is fired, and the "Move and Scale" view is displayed. Upon pressing "choose", the delegate gets called, and I am able to access the editing result via info
.
所以这是我的新初始化代码,带有自定义的拍照按钮,没有别的;顺便说一句,我正在我的ViewController的viewDidAppear方法中初始化这个UIImagePickerController
So here's my new initialization code with a custom "take photo" button and nothing else; by the way, I'm initializing this UIImagePickerController in the viewDidAppear method of my ViewController
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];
在这个例子中,当我点击我的自定义按钮时,没有动画被触发,没有显示编辑屏幕,代表被立即调用。
In this example, when I hit my custom button, no animations are fired, no editing screen is shown, the delegate is called immediately.
有趣的是,如果我只是将 showsCameraControls
属性更改为<$ c在上面的示例中,$ c> YES ,我的自定义按钮的行为与第一个示例中默认按钮的行为完全相同。
Funny thing is, if I just change the showsCameraControls
property to YES
in the above example, my custom button behaves exactly the way the default button behaves in my first example.
非常难倒这个,我需要在 didFinishPickingMediaWithInfo
中调用图像编辑器,或者我刚刚在初始化时遗漏了什么?
Pretty stumped on this one, is there something I need to do in didFinishPickingMediaWithInfo
to invoke the image editor, or am I just missing something in my initialization?
我正在使用Xcode 4.3和iOS 5.1(该应用程序的目标是5.0)
I'm using Xcode 4.3 and iOS 5.1 (the app is targeted for 5.0)
任何帮助都非常感谢;干杯!
Any help greatly appreciated; Cheers!
推荐答案
显然,移动和裁剪功能是默认相机控件的一部分
So apparently the "Move and Crop" functionality is part of the default camera controls
当您使用照片库作为源时,唯一的选择是默认选项,因此它始终有效。
When you use photo library as your source, the only option is default, so it always works.
最后,我写了我的拥有移动和裁剪视图,使用简单的滚动视图和一些叠加视图来表示裁剪框。
In the end, I wrote my own "move and crop" view using a simple scroll view and some overlay views to represent the crop box.
不太难,只需要根据缩放做一些数学运算UIScrollView的因子和内容偏移。
Not too hard, just have to do some math based on zoom factor and contentoffset of the UIScrollView.
这篇关于UiImagePickerController takePicture问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!