2

I've read almost every post around here regarding my problem but none of the solutions seems to work on my app.

So, I use a custom camera view (with buttons on toolbar and an overlay) that is being presented modally from a view controller. My app only supports landscape left and right for the orientation. And i want to stop the camera view from autorotating when it's being presented. I've put all the methods needed for autorotation on my view controller and my app delegate. I've checked on my plist file too and the supported rotations are correct. But my camera view keeps on rotating to any rotation (portrait and landscape) when I rotate the device, resulting on the overlay and the toolbar being incorrectly positioned. I also can't check on the camera view's orientation because i tried putting NSLog on shouldAutoRotate method, but it doesn't get called at all.

So how can I check the rotation on my custom camera view? And how can I force it to not rotate and stay still?

If my code is needed, I'll post it here. If anyone can help me on it I'll greatly appreciate it because it frustrates me so much right now.

Thank you. Cheers.

tyegah123
  • 197
  • 3
  • 13

3 Answers3

2

Create a new class of "UIImagePickerController" and implement the rotation delegates in the .m file as given,

// For lower iOS versions
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation  {

return ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || ((toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)));
}

// For iOS version 6.0 and above
- (BOOL)shouldAutorotate {

return YES;
}


- (NSUInteger)supportedInterfaceOrientations {

return (UIInterfaceOrientationMaskLandscape);
}

And make an instance of lets say MyImagePickerController instead of UIImagePickerController, and present it. This will work :)

Augustine P A
  • 5,008
  • 3
  • 35
  • 39
0

Create a category for UINavigationController

@interface UINavigationController(autoRotation)

-(BOOL)shouldAutoRotate;

@end

@implementation UINavigationController

-(BOOL)shouldAutoRotate{

  return [[self.viewControllers lastobject] shouldAutoRoatate];

}

-(NSUInteger)supportedInterfaceOrientations {

  return [[self.viewControllers lastobject] supportedInterfaceOrientations];

}

@end

Implement these two methods in your corresponding view controllers and return the orientation what u exactly want....

Deepesh
  • 8,065
  • 3
  • 28
  • 45
jailani
  • 2,260
  • 2
  • 21
  • 45
  • Thank you for answering. But I've also tried this method already. Didn't give me the result that I wanted. But maybe I was missing something. So, maybe I'll try tinkering more with this method. – tyegah123 May 08 '13 at 05:54
  • How do you bring your cameraview? using presentModalViewController? If yes your UIImagePickerViewController does't exist in your navigation stack. So you have to create a category for your IMagePickerViewController and call shouldAutoRotae... – jailani May 08 '13 at 06:16
  • Yes, I am using presentModalViewController. Can you give me the example code to create the category? I'll definitely try it out cuz it seems like it is the way. – tyegah123 May 08 '13 at 07:37
0

xcode -> file -> new file select cocotouch in the leftpane select objective-c category ->next select give name Picker category on UIImageImagePickerController from dropdown

import

@interface UIImagePickerController (picker)

-(BOOL)shouldAutoRotate; -(NSUInteger)supportedInterfaceOrientations;

@end

import "UIImagePickerController+picker.h"

@implementation UIImagePickerController (picker)

-(BOOL)shouldAutoRotate{

    return yourOrientation;

}

-(NSUInteger)supportedInterfaceOrientations {

    return yourInteger;

}

@end

After this when your device's orientation changed then the method shouldAutoRotate get called from your UINavigationController category at this time you have to find out if cameraview is presented if yes then you have to call shouldAutoRotate of Picker

See the following code

in your view controller's shouldAutoRotate

-(BOOL)shouldAutoRotate{

   if([self presentingViewController])// Camera is present 
         return [instanceOfUIImagePickerController shouldAutoRotate];
   return yourOrientaionNeededForThisVC;

}

jailani
  • 2,260
  • 2
  • 21
  • 45