Reputation: 1013
I am newbie in IOS.I working on the demo project in which I am supposed to open UIImagepicker to pick photos and Camera to capture new one, in all orientation. I know UIImagepicker supports only portrait orientation, but I have made a category class of UIImagePicker and in which i override the orientation methods to support orientation.
The issue is my UIImagePicker gets open perfectly in all orientation but the camera gets rotated 90 degree and comes in half screen when i change to any landscape mode.
So to solve this issue I added one observer which fires a notification when orientation changes.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
And the method which is called is
- (void) orientationChanged
{
if (self.imagePickerController.sourceType==UIImagePickerControllerSourceTypeCamera)
{
@try {
if (orientation == UIInterfaceOrientationLandscapeLeft)
{
transform=CGAffineTransformRotate(transform,LANDSCAPE_NEGATIVE_ANGLE * M_PI / LANDSCAPE_ANGLE);
transform=CGAffineTransformTranslate(transform, -75, -80);
[self.imagePickerController setCameraViewTransform:transform];
}
else if (orientation == UIInterfaceOrientationLandscapeRight)
{
transform=CGAffineTransformRotate(transform,LANDSCAPE_NEGATIVE_ANGLE * M_PI / LANDSCAPE_ANGLE);
transform=CGAffineTransformTranslate(transform, 75, 80);
[self.imagePickerController setCameraViewTransform:transform];
}
else
{
// CGAffineTransform tmpTransform=PORTRAIT_Transform;
transform=CGAffineTransformRotate(transform,LANDSCAPE_NEGATIVE_ANGLE * M_PI / 90);
transform=CGAffineTransformTranslate(transform, 0, 0);
[self.imagePickerController setCameraViewTransform:transform];
}
}
@catch (NSException *exception)
{
NSLog(@"Exception occured, Details :%@",exception);
}
@finally {
}
}
}
This method works fine for me when I open camera in portrait mode and then I change to other orientation. But when I open the camera in landscape mode all things mess up. I know i used static values here but I didn't had any other choice.
Does anyone have any suggestion or alternative option. I will be really thankful to him/her.
Thanks in advance !!!
Upvotes: 2
Views: 2057
Reputation: 2523
These answer can help you :
iPhone UIImagePicker Camera in Landscape Orientation
or
iOS UIImagePickerController result image orientation after upload
Nice way to do this.
Upvotes: 1