Lock UIImagePickerController in Portrait mode in ios app

In my iOS app, when I open the camera, I put the image on the camera. It looks good in portrait mode. But when it is changed in landscape mode, it looks a little strange. So I want to lock UIImagePickerControllerin portrait mode.

Below is my code for ui image select controller

UIImagePickerController *imgPkr = [[UIImagePickerController alloc] init];
imgPkr.delegate = self;
imgPkr.sourceType = UIImagePickerControllerSourceTypeCamera;

How can it be blocked in portrait mode ....

+5
source share
8 answers

This is not the best solution, but it works:

AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
[appDelegate.window addSubview:cameraOverlay];
imgPicker.cameraOverlayView = appDelegate.window.superview;

The camera in the background is still rotating, but your overlay view is not working. Hope this works for you.

+2
source

Or you can subclass UIImagePickerController:

UIImagePickerController .

- (BOOL)shouldAutorotate{
return NO;
}

, , UIImagePickerController .

.

+3

, , , :

#import "UIImagePickerController+NoRotate.h"

@implementation UIImagePickerController (NoRotate)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
@end

!

+2

" UIImagePicker ". , " , ", , , . UIImagePicker . : AViewController . BViewController subview AViewController. presentModalViewController:UIImagePickerController BViewController. UIImagePicker .

UIImagePickerController presentModelViewController. :

- (void) onCameraButtonTapped:(UIBarButtonItem *)buttonItem
{   
    //backupRootController it use as a backup, it will recover after close the image picker controller.
    self.backupRootController = [[UIApplication sharedApplication] keyWindow].rootViewController;

    UIImagePickerController * imageController = [[UIImagePickerController alloc] init];
    imageController.sourceType = UIImagePickerControllerSourceTypeCamera;
    imageController.delegate = self;
    ....
    [[[UIApplication sharedApplication] keyWindow] setRootViewController:imageController];
    [self presentModalViewController:imageController animated:YES];
    [imageController release];
}


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [[[UIApplication sharedApplication] keyWindow]  setRootViewController:self.backupRootController];
    ....
}

, . --Goman

+1

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
0

UIImagePickerController shouldAutoRotateToInterfaceOrientation :

@implementation UIImagePickerController (NoRotate)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
0
-(BOOL)shouldAutorotate {
return NO;}

. . : ios6.0

0

, uiimagepickercontroller - (BOOL) shouldAutorotate { return NO; }

0

All Articles