问题
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:
(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];
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
.
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.
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.
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?
I'm using Xcode 4.3 and iOS 5.1 (the app is targeted for 5.0)
Any help greatly appreciated; Cheers!
回答1:
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.
Not too hard, just have to do some math based on zoom factor and contentoffset of the UIScrollView.
来源:https://stackoverflow.com/questions/11440665/uiimagepickercontroller-takepicture-issues