Auto layout in camera overlay mode - cannot center button vertically
I am trying to add an overlay to a camera. For this, I created the following event method:
- (IBAction)takePhoto:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
imagePicker.showsCameraControls = NO;
imagePicker.navigationBarHidden = YES;
imagePicker.toolbarHidden = YES;
imagePicker.wantsFullScreenLayout = YES;
// Overlay
// Insert the overlay
self.overlay = [[OverlayViewController alloc] initWithNibName:@"OverlayView" bundle:nil];
//[self.overlay.view setTranslatesAutoresizingMaskIntoConstraints:NO];
self.overlay.pickerReference = imagePicker;
imagePicker.cameraOverlayView = self.overlay.view;
imagePicker.delegate = self.overlay;
[self presentViewController:imagePicker animated:NO completion:nil];
} else{
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePicker setDelegate:self];
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
The button is centered like this.
But it looks like an iPhone 4 in use. It is not vertically centered. If I try to connect the Slikaj button to the bottom, it is not visible because the screen size of the iPhone 4 is smaller than the iPhone 5. The "Use automatic layout" checkbox is checked (enabled). What am I doing wrong?
+3
source to share
1 answer
There are other frame sizes in your overlay view for some reason. You can fix this by assigning frame dimensions to imagePicker
your overlay view.
self.overlay = [[OverlayViewController alloc] initWithNibName:@"OverlayView" bundle:nil];
self.overlay.pickerReference = imagePicker;
self.overlay.frame = imagePicker.cameraOverlayView.frame;
imagePicker.cameraOverlayView = self.overlay.view;
imagePicker.delegate = self.overlay;
+2
source to share