How to change camera Overlayview orientation landscape left and right iPhone?
Asked Answered
E

1

8

In my iPhone application i have a UIImagePickerController for take photos. I have hide all default camera controls and added UIView with Two button as a CameraOverLayView in UIImagePickerController. My application is always run in Landscape mode only. The Camera is also launching Landscape mode only. Now, the CameraOverlayView is only in Landscape Left side not change to Landscape to Right. How can i change the CameraOverlayView LandscapeMode Left and Right when the device orientation will changing? Please help me to fix it. It is major problem in my app. This code hold the Overlayview in Landscape mode Left

imgpicker.cameraOverlayView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, 117.81);

and this code hold the cameraoverlayview in Landscape mode right GAffineTransform transform = self.view.transform;

    transform = CGAffineTransformRotate(transform, (M_PI / 2.0));

    imgpicker.cameraOverlayView.transform = transform;

I used these codes in UIInterfaceOrientation methods like this,

UIInterfaceOrientation orientation= [[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIInterfaceOrientationLandscapeLeft) 
    {
        imgpicker.cameraOverlayView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, 117.81);
    }
    else if (orientation == UIInterfaceOrientationLandscapeRight)
    {
        CGAffineTransform transform = self.view.transform;
            transform = CGAffineTransformRotate(transform, (M_PI / 2.0));
        imgpicker.cameraOverlayView.transform = transform;
    }

But, these are not helping me. When i rotate the device orientation landscape left and right, the cameraoverlayview does not changing. Can you please fix my problem? Thanks.

Eaglewood answered 2/12, 2011 at 13:8 Comment(0)
E
16

Thanks to all. I have solved the Camera OverlayView orientation problem by myself. I have used the same code mentioned in my question. Just i have added UIDeviceOrientation Notification for the orientation changes. Please find the code below,

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];


- (void) orientationChanged:(NSNotification *)notification
{
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if(orientation == UIDeviceOrientationLandscapeLeft)
        {                  
            CGAffineTransform transform = self.view.transform;
            transform = CGAffineTransformRotate(transform, (M_PI/2.0));
            imgpicker.cameraOverlayView.transform = transform;
        } 
        else if(orientation == UIDeviceOrientationLandscapeRight) 
        {   
            imgpicker.cameraOverlayView.transform = CGAffineTransformRotate(CGAffineTransformIdentity,117.81);
        }  
}

I just added this method additionally in my code. So that when the user change the device orientation this method will call and change camera overlay view's orientation. Please check your conditions inside this method otherwise app will getting crash. Thanks.

Eaglewood answered 19/1, 2012 at 6:14 Comment(1)
I'm using this and my overlay never lines up correctly. Its always too far left or right.Cleancut

© 2022 - 2024 — McMap. All rights reserved.