问题
I have got a UIButton inside a UIView that I set as the cameraOverlayView.
I also scaled the uiimagepicker cameraView to cover the whole screen (as you can see below in the picture).
Here's my code :
// CameraViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
if(!self.imagePickerController)
[self setupCamera];
}
-(void)setupCamera{
self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.imagePickerController.delegate = self;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePickerController.showsCameraControls = NO;
self.imagePickerController.cameraOverlayView = self.overlayView;
[self scaleCameraPreview];
// Present picker in the next loop (to avoid warning - "Presenting view controllers on detached view controllers is discouraged")
[self performSelector:@selector(presentPicker) withObject:nil afterDelay:0.0];
}
-(void)presentPicker{
[self presentViewController:self.imagePickerController animated:NO completion:nil];
}
-(void)scaleCameraPreview{
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
int heightOffset = 0;
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
{
heightOffset = 120;
}
float cameraAspectRatio = 4.0 / 3.0;
float imageWidth = floorf(screenSize.width * cameraAspectRatio);
float scale = ceilf(((screenSize.height + heightOffset) / imageWidth) * 10.0) / 10.0;
self.imagePickerController.cameraViewTransform = CGAffineTransformMakeScale(scale, scale);
}
-(IBAction)cameraButtonPressed:(id)sender{
[self.imagePickerController takePicture];
}
And this is my hierarchy of viewcontrollers:
- UINavigationController
- SWRevealViewController (manages a drawer functionality between different controllers)
- UINavigationController (current controller for the camera)
- CameraViewController
- PickerViewController (Presented modally as you can see above)
- PhotoTakenViewController (Controller that will fire after UIImagePicker returns an image)
EDIT: Adding overlay info
I have searched online for similar threads (e.g. UIImagePickerController Overlay Buttons Not Firing) but didn't find any solution.
The UIButton that you can see in the picture, is inside a UIView this is the overlayView in the code assigned to the cameraOverlayView. It is also connected to the cameraButtonPressed: action through an outlet, and it works perfectly if I don't add the UIImagePickerController.
It isn't responding to any touches I don't know why.
Does anyone know what's going on?
回答1:
I've fixed my issue but I believe in a sketchy way:
[self presentViewController:self.imagePickerController animated:NO completion:^(void){
// Re-add the button so it is on top of the overlay
[self.imagePickerController.view addSubview:self.takePhotoButton];
}];
Will probably come back later to this issue and post an update in case I find a better solution.
来源:https://stackoverflow.com/questions/27498203/uibutton-inside-uiimagepickercontroller-cameraoverlayview-not-responding