Reputation: 241
I created a custom overlay for the camera, using the following code:
- (void) showCamera {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;
self.overlay = [[CameraOverlayViewController alloc] init];
self.overlay.pickerReference = self.picker;
self.picker.cameraOverlayView = self.overlay.view;
self.picker.delegate = self.overlay;
[self presentViewController:self.picker animated:NO completion:nil];
}
It works fine on iphone 4 (as the camera covers the entire screen), but on iphone 5 the camera is on the top of the screen, leaving black square at the bottom. As I cannot change the camera size, at least I want to center it in the middle of the screen, and then add UIViews as margins (quite similar to apple's Camera Roll app, where the camera is not on the top of the screen, and there are controls both above and below it).
Can someone please advise how can I control the camera frame in such scenario? Also, as the margins will be only for nicer visualisation, I may not want to show them on iphone 4 or ipad screen.
Thanks in advance !
Upvotes: 3
Views: 1354
Reputation: 481
Since we know that the camera will always be the same length of the screen width:
//getting the camera height by the 4:3 ratio
int cameraViewHeight = SCREEN_WIDTH * 1.333;
// get the difference between the screen height and the camera height. Distribute by dividing by 2.
int adjustedYPosition = (SCREEN_HEIGHT - cameraViewHeight) / 2;
// adjust the image picker controller
CGAffineTransform translate = CGAffineTransformMakeTranslation(0, adjustedYPosition);
self.imagePicker.cameraViewTransform = translate;
Upvotes: 1
Reputation: 8715
Use cameraViewTransform
property to change camera's y
position. For example:
if(IS_IPHONE_5){
CGAffineTransform tr = self.imagePickerController.cameraViewTransform;
tr.ty = 70;
self.imagePickerController.cameraViewTransform= tr;
}
where IS_IPHONE_5
is:
#define IS_IPHONE_5 ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
Upvotes: 1