Restricting an application to a specific orientation on IOS 5 - ios

I have an IOS application developed using Cocos2dx engine.
The application is locked for a specific orientation (for example portrait)
everything in the application seems to work fine and according to the right orientation except for the recent apps bar and notifications which are according to the device orientation.
I want to be able to restrict it so it will have the same orientation as the application itself.
I noticed that removing the landscape orientation inside the info.plist file does the job, but I want to be able to do it through code.
In IOS 6 I found that all I had to was to override referredInterfaceOrientationForPresentation in my RootViewController
and give the right orientation and this does the trick,
but this method doesn't work for IOS 5 and below.
What do I need to do to make this work on devices with IOS 5 and below?
This is the code for the RootViewController (I didn't write it, I just added the last method and I'm trying to figure out how to fix the notifications and recent apps problem)
#include "cocos2d.h"
#import "RootViewController.h"
#import "AppDelegate.h"
#import "misc/deviceOrientation.h"
#import "services/ios/ConfigurationServiceImpl.h"
#implementation RootViewController
#synthesize progressView;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
-(NSUInteger)supportedInterfaceOrientations{
ConfigurationServiceImpl* configurationService = [ConfigurationServiceImpl instance];
if ([configurationService isLandscape])
return UIInterfaceOrientationMaskLandscape;
else
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
-(BOOL)shouldAutorotate{
return YES;
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// printf("shouldAutorotateToInterfaceOrientation\n");
//
// There are 2 ways to support auto-rotation:
// - The OpenGL / cocos2d way
// - Faster, but doesn't rotate the UIKit objects
// - The ViewController way
// - A bit slower, but the UiKit objects are placed in the right place
//
#if GAME_AUTOROTATION==kGameAutorotationNone
//
// EAGLView won't be autorotated.
// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
//
return ( interfaceOrientation == UIInterfaceOrientationPortrait );
#elif GAME_AUTOROTATION==kGameAutorotationCCDirector
//
// EAGLView will be rotated by cocos2d
//
// Sample: Autorotate only in landscape mode
//
if( interfaceOrientation == UIInterfaceOrientationLandscapeLeft ) {
[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeRight];
} else if( interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[[CCDirector sharedDirector] setDeviceOrientation: kCCDeviceOrientationLandscapeLeft];
}
}
// Since this method should return YES in at least 1 orientation,
// we return YES only in the Portrait orientation
return ( interfaceOrientation == UIInterfaceOrientationPortrait );
#elif GAME_AUTOROTATION == kGameAutorotationUIViewController
//
// EAGLView will be rotated by the UIViewController
//
// Sample: Autorotate only in landscpe mode
//
// return YES for the supported orientations
ConfigurationServiceImpl* configurationService = [ConfigurationServiceImpl instance];
return [configurationService shouldAutorotateToInterfaceOrientation: interfaceOrientation];
#else
#error Unknown value in GAME_AUTOROTATION
#endif // GAME_AUTOROTATION
// Shold not happen
return NO;
}
//This callback only will be called when GAME_AUTOROTATION == kGameAutorotationUIViewController
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
CDeviceOrientation::setDeviceOrientation(CDeviceOrientation::left);
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
CDeviceOrientation::setDeviceOrientation(CDeviceOrientation::right);
else if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
CDeviceOrientation::setDeviceOrientation(CDeviceOrientation::down);
else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
CDeviceOrientation::setDeviceOrientation(CDeviceOrientation::up);
}
#endif // GAME_AUTOROTATION == kGameAutorotationUIViewController
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
ConfigurationServiceImpl* configurationService = [ConfigurationServiceImpl instance];
if ([configurationService isLandscape])
return UIInterfaceOrientationLandscapeRight;
else
return UIInterfaceOrientationPortrait;
}
#end

Use shouldAutorotateToInterfaceOrientation for iOS 5 and shouldAutorotate for iOS 6. In iOS5 method, use if case for your supported orientations and return YES for them. In your app summary, enable all the orientations. Hope these will help you.

I make this code skeleton for dealing with wanted & unwanted devices orientations, in my case i want to ignore the UIDeviceOrientationUnknown, UIDeviceOrientationFaceUp and UIDeviceOrientationFaceDown, caching the last allowed orientation. This code deals with iPhone and iPad devices and can be useful for you.
- (void)modXibFromRotation {
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
NSString *device = [[UIDevice currentDevice]localizedModel];
UIInterfaceOrientation cachedOrientation = [self interfaceOrientation];
if ([device isEqualToString:#"iPad"]) {
if (orientation == UIDeviceOrientationUnknown ||
orientation == UIDeviceOrientationFaceUp ||
orientation == UIDeviceOrientationFaceDown) {
orientation = (UIDeviceOrientation)cachedOrientation;
}
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) {
/* Your code */
}
if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
/* Your code */
}
}
if ([device isEqualToString:#"iPhone"] || [device isEqualToString:#"iPod"]) {
if (orientation == UIDeviceOrientationUnknown ||
orientation == UIDeviceOrientationFaceUp ||
orientation == UIDeviceOrientationFaceDown) {
orientation = (UIDeviceOrientation)cachedOrientation;
}
if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight) {
/* Your code */
}
if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
/* Your code */
}
}
}
Yo have to call this method from two places in your view controller:
Fist begin generating device Orientation Notifications in your App delegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//**** ADD THIS CODE *****
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
// Add the main view controller's view to the window and display.
self.window.rootViewController = self.mainViewController;
[self.window makeKeyAndVisible];
return YES;
}
then listen for device Orientation Notifications in your view controller:
- (void)viewDidLoad {
[notificationCent addObserver:self
selector:#selector(modXibFromRotation)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
Finally call the modXibFromRotation method from:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear];
[self modXibFromRotation];
}
This will call the check orientation method before the view is shown.

Related

Device Orientation not getting.

Currently i am working on IOS 7 and my problem is i am not able to get orientation of current device in ViewDidLoad method.
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAll);
}
- (void)viewDidLoad
{
[super viewDidLoad];
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){
NSLog(#"i am in landscape mode");
}
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){
NSLog(#"i am in portrait mode");
}
}
I write this code in my FirstViewController.m,and when i run my application no condition become true out of them,
can anybody help me why no condition become true even i run my application in portrait mode.
Thanks in advance.
Try this.
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if(UIInterfaceOrientationIsLandscape(orientation)) {
//Landscape mode
}
else
{
//Portrait mode
}
EDIT : Use UIInterfaceOrientationIsLandscape and UIInterfaceOrientationIsPortrait method to find orientation mode
try this
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIDeviceOrientationIsLandscape(orientation))
{
NSLog(#"i am in landscape mode");
}
if (UIDeviceOrientationIsPortrait(orientation)){
NSLog(#"i am in portrait mode");
}
oky u hav other orientation call back methods this one called before rotation is going to occur - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration and this one just after second one - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation, for example
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
UIInterfaceOrientation orientation = toInterfaceOrientation; //hear toInterfaceOrientation contains the which orientation is device is turning to
if (UIDeviceOrientationIsLandscape(orientation))
{
NSLog(#"i am in landscape mode");
}
if (UIDeviceOrientationIsPortrait(orientation)){
NSLog(#"i am in portrait mode");
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIInterfaceOrientation orientation = fromInterfaceOrientation; // hear fromInterfaceOrientation contains previous state of the orientation
if (UIDeviceOrientationIsLandscape(orientation))
{
NSLog(#"i am in landscape mode");
}
if (UIDeviceOrientationIsPortrait(orientation)){
NSLog(#"i am in portrait mode");
}
}
for more information see docs
hope this helps u .. :)

How to hide ImageView (landscape) if device is lying on a table or another straight surface?

I am having some problems with my application.
In some Views I want to hide a textview or an ImageView, if the device is in the landscape orientation. I was testing on a real device now and got some problems with my code, if I was lying the device on a straight surface like a table, my code doesn't hide the Image/TextView.
In my ViewDidLoad I use this:
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{
// code for landscape orientation
[textview setHidden:YES];
}
and I use the following code, if the user rotate the device:
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[textview setHidden:YES];
} else {
[textview setHidden:NO];
}
}
The code works fine, when I hold the device in my hands, but it doesn't work if the device lies on a straight surface.
How can I handle this problems?
iPhone gyroscope/accelerometer works based on the gravity, and that requires moving the phone with some motion in space, if you get me. However if you want to define a certain event for that mode, you should include UIDeviceOrientationFaceUp in your code. See UIDevice Class Reference for more info.
typedef enum {
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait,
UIDeviceOrientationPortraitUpsideDown,
UIDeviceOrientationLandscapeLeft,
UIDeviceOrientationLandscapeRight,
UIDeviceOrientationFaceUp,
UIDeviceOrientationFaceDown
} UIDeviceOrientation;
Try something like this:
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationFaceUp))
{
//your code for landscape orientation
//[textview setHidden:YES;
}
If you want to check when the phone is lying flat. use UIAccelerometer.
in .h set delegate
#interface AccelerometerViewController : UIViewController
<UIAccelerometerDelegate> {
}
in .m
- (void)viewDidLoad {
UIAccelerometer *accel = [UIAccelerometer sharedAccelerometer];
accel.delegate = self;
accel.updateInterval = 1.0f/1.0f;
[super viewDidLoad];
}
- (void)accelerometer:(UIAccelerometer *)acel
didAccelerate:(UIAcceleration *)acceleration
{
//this checks if flat down
if (acceleration.z < -1.0)
{
//this checks if rotate left
if (acceleration.x < (-0.00) && acceleration.y > 0.00)
{
NSLog(#"rotate left");
//hide textView here
}
//this checks if rotate right
if (acceleration.x > 0.0 && acceleration.y > 0.00)
{
NSLog(#"rotate right");
//hide textView here
}
}
}

Use camera in Landscape only app -iOS

I have an application that supports only landscape mode. When I opening the camera the app crashes. I solved the problem by using the following code.
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(BOOL)shouldAutorotate {
return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait;
}
But the app turns to support all orientations. All I want is the app only support landscape mode and also uses camera.
Any help will be appreciated.
I finally figured it out. The shouldAutorotate never gets called in ViewControllers. Because the topmost view controller has to return the interface orientations it wants to rotate to. In my case, that's the UINavigationController. So I creates the new category for UINavigationController to make it work. I uses the following methods in the category
#implementation UINavigationController (BugiOSFix)
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(BOOL)shouldAutorotate {
return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait;
}
#end
Write this For orientations .........
-(void)viewWillAppear:(BOOL)animated
{
[self willAnimateRotationToInterfaceOrientation:
[UIApplication sharedApplication].statusBarOrientation duration:1.0];
UIInterfaceOrientation orientation =
[UIApplication sharedApplication].statusBarOrientation;
if(orientation == UIInterfaceOrientationLandscapeRight ||
orientation == UIInterfaceOrientationLandscapeLeft)
{
[self setFrameForLeftAndRightOrientation];
}
else if(orientation == UIInterfaceOrientationPortrait )
{
[self setFrameForPortraitAndUpsideDownOrientation];
}
}
- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[self setFrameForLeftAndRightOrientation];
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
[self setFrameForPortraitAndUpsideDownOrientation];
}
}
-(void)setFrameForLeftAndRightOrientation
{
if(IS_IPAD)
{
// Write here for left and right orientation
}
else if(is_iPhone)
{
// Write here for iPhone land scape ;
}
-(void)setFrameForPortraitAndUpsideDownOrientation
{
if(IS_IPAD)
{
// Write here for Portrait orientation for iPad
}
else if(is_iPhone)
{
// Write here for iPhone Portrait orientation ;
}
}
See my answer at How to create a landscape-view only ios application for a similar question. All you have to do is to implement one method and your app will be forced to autorotate to the direction you want it.
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
This will force your app to rotate to the UIInterfaceOrientationLandscapeLeft direction by providing your ViewController with only one preferred orientation.

Orientation issue in iPad ios6

I check the orientation of the device in viewDidAppear and viewWillAppear and force the orientation by calling willAnimateRotationToInterfaceOrientation method.
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
_levelComplete = YES;
[self willAnimateRotationToInterfaceOrientation:[[UIDevice currentDevice] orientation] duration:0.01];
}
- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight) )
{
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
}
}
The problem i face is that toInterfaceOrientation is remains 0 for both viewDidAppear and viewWillAppear method hence program crashes.
What might be the problem?
Please Help!
Try this
- (void) viewDidLoad
{
_levelComplete = YES;
[self adjustViewsForOrientation:self.interfaceOrientation];
}
-(void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation
{
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
}
else
{
}
}
As you mentioned : The problem i face is that toInterfaceOrientation is remains 0 for both viewDidAppear and viewWillAppear method hence program crashes.
The orientation 0 refers to unknown orientation. Set the break point on viewWillAppear and viewDiddAppear and on orientation delegates. Note that do the delagates of orientation gets called first of the view delegates.
You can use the delegate
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
Using this delegate and the application will be present in Landscape mode or any desired orientation mode.
Try it.

ios6 autorotation portraitupsidedown to portrait

Please don't suggest me it is a bad idea to have the rotation at ios 4.3-6.0 in 1 build, because I told to many times and didn't listen to me.
At project settings I have setted all interface orientations to be supported, just to be sure.
Right now I am testing on ios6 with iphone4. Starting at app delegate it is a code, like this:
mainController = [[MainViewController alloc] initWithNibName:nil bundle:nil];
navigationController=[[RotatingNavigationController alloc] initWithRootViewController:mainController];
navigationController.navigationBar.hidden =true;
// ios: 4 and 5
//[window addSubview:navigationController.view];
//ios6:
window.rootViewController = navigationController;
[window makeKeyAndVisible];
So I did 2 custom classes, which are recommended in may cases for autorotations, and for they the problem is solved.
The RotatingNavigationController is a custom UINavigationController has a bit ugly code, but I have collected this parts from this forum, so it should be allowed to post it:
#implementation RotatingNavigationController
- (id)init {
self = [super init];
if (self) {
self.view.autoresizesSubviews = YES;
[self.view setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];
}
return self;
}
// ios6 require this method for rotation detection, available from ios5, ios4.3 not available: sux
//- (void)viewWillLayoutSubviews
//{
//UIInterfaceOrientation statusBarOrientation = [UIApplication sharedApplication].statusBarOrientation;
//[[NSNotificationCenter defaultCenter] postNotificationName:UIDeviceOrientationDidChangeNotification object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
/*
if(UIInterfaceOrientationIsLandscape(statusBarOrientation)){
[self willRotateToInterfaceOrientation: statusBarOrientation duration: 0.3 ];
}
else{
[self willRotateToInterfaceOrientation: statusBarOrientation duration: 0.3 ];
}
*/
//}
//ios 4.3 and ios 5.0, at ios6 it isn't called by iOS...sux
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[self.visibleViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
// //ios 4.3 and ios 5.0, at ios6 need different methods, which sux
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
//Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientationsForWindow: and shouldAutorotate methods.
// ios6
- (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAll;
}
// ios6
- (BOOL)shouldAutorotate
{
return YES;
}
// ios6
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskPortrait;
}
#end
this should generate the autorotation notifications properly, I think he it does his job.
The MainViewController is a custom UIViewController.
just to be sure I have copy-pasted the code:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
// return (interfaceOrientation == UIInterfaceOrientationPortrait);
return YES;
}
// ios6:
- (NSUInteger)supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskAll;
}
// ios6
- (BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskPortrait;
}
His job is to change the different UIViewController based on device state ( rotations )
I have somewhere a Menu screen, which has different xib, but h and m file too ( because has different elements, which doesn't appear in Portait or Landscape. ( I don't have the power to change the whole architecture )
A part of the code - and here should be some problem, I think is below in this Maincontroller:
#pragma mark
#pragma mark Rotation
- (void)orientationChanged:(NSNotification *)notification
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
UIInterfaceOrientation statusBarOrientation = [UIApplication sharedApplication].statusBarOrientation;
if(deviceOrientation == UIDeviceOrientationFaceUp || deviceOrientation == UIDeviceOrientationFaceDown){
if(debug){
NSLog(#"Nothing to change because it is gone to Flat");
}
return;
}
NSArray *viewControllers = [self.navigationController viewControllers];
if (UIDeviceOrientationIsLandscape(deviceOrientation)){
//if(debug)
// NSLog(#"Portait -> Landscape size : %3.0fw, %3.0fh", self.view.bounds.size.width, self.view.bounds.size.height);
id lastviewController = viewControllers.lastObject;
// check what is there:
if([lastviewController isKindOfClass:[MenuController class]]){
[self.navigationController popViewControllerAnimated:NO];
[self.navigationController pushViewController:menuLandscape animated:NO];
NSLog(#"poped Menu Portrait, pushed Menu Landscape");
}
...
else if(UIDeviceOrientationIsPortrait(deviceOrientation)){
//else if(UIInterfaceOrientationIsLandscape(statusBarOrientation)){
//if(debug)
// NSLog(#"Landscape -> Portait , size : %3.0fw, %3.0fh", self.view.bounds.size.width, self.view.bounds.size.height);
id lastviewController = viewControllers.lastObject;
// check what is there:
if([lastviewController isKindOfClass:[MenuLandscapeController class]]){
[self.navigationController popViewControllerAnimated:NO];
[self.navigationController pushViewController:menuPortait animated:NO];
}
...
The problem is: the landscape is taken out and is pushed the portait, when is upside down, but that portait aren't rotating and it shows a broken layout.
How can I wake up that controller and tell him is time to rotate, because it isn't in portrait mode?
Thanks any suggestion related to my question of any improvement beside of architecture change.
Update:
at app delgate doesn't helped adding the:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}
code from other answer: presented here
Update2:
UIInterfaceOrientation statusBarOrientation = [UIApplication sharedApplication].statusBarOrientation;
doesn't want to take the UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown value for some reason, I think that need to be solved.
Update3:
Read very carefully twice and third the ios6 release notes
The system determines whether an orientation is supported by
intersecting the value returned by the app’s
supportedInterfaceOrientationsForWindow: method with the value
returned by the supportedInterfaceOrientations method of the top-most
full-screen controller.
now read again :)
Add this category to viewcontroller which doesn't rotate
#implementation UINavigationController(Rotation)
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
#end

Resources