Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 783
Yuvaraj.M Avatar asked Dec 02 '11 13:12

Yuvaraj.M


People also ask

What is landscape left and right?

LandscapeLeft: The device is in landscape mode, with the device held upright and the home button on the right side. LandscapeRight: The device is in landscape mode, with the device held upright and the home button on the left side.

What is device orientation in Xcode?

You can configure which device orientation does your iOS app support in the Xcode target —> General —> Deployment Info section also. Just check the checkbox in the Deployment Info —> Device Orientation section. Below is the explanation of each orientation meaning, you can check multiple checkboxes.


1 Answers

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.

like image 131
Yuvaraj.M Avatar answered Nov 06 '22 23:11

Yuvaraj.M