Reputation: 1954
I have implemented a custom camera in my app using UIImagePickerController
. I previously made the camera full screen by applying this transformation:
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.showsCameraControls = NO;
[[NSBundle mainBundle] loadNibNamed:@"SnapItCameraView" owner:self options:nil];
self.overlayView.frame = ipc.cameraOverlayView.frame;
ipc.cameraOverlayView = self.overlayView;
self.overlayView = nil;
//For iphone 5+
//Camera is 426 * 320. Screen height is 568. Multiply by 1.333 in 5 inch to fill vertical
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, 71.0); //This slots the preview exactly in the middle of the screen by moving it down 71 points
ipc.cameraViewTransform = translate;
CGAffineTransform scale = CGAffineTransformScale(translate, 1.333333, 1.333333);
ipc.cameraViewTransform = scale;
ipc.showsCameraControls = NO;
ipc.tabBarController.tabBar.hidden = YES;
ipc.allowsEditing = NO;
[self presentViewController:ipc animated:YES completion:nil];
}
However, the camera does not fill the screen of the iPhone X. Its flush with the top of the screen, but there is a black bar at the bottom.
I assume the issue is that 1.3 is the wrong scale to vertically fill the screen. I would like the camera to fill the entire screen of the phone for the iPhone X.
Upvotes: 0
Views: 863
Reputation: 2587
Hard-coding that ratio doesn't make much sense here if you can calculate it instead.
You calculated 1.3333 by dividing screen height (568) by the height of the camera view (426). That logic should work the same on the X but you need to provide the correct parameters instead of assuming all phones share the same screen dimensions.
Also keep in mind that transforming this image may result in parts of it being cut off if you chose to scale proportionately.
Upvotes: 1