Considering:
View A: Portrait only - View B: Landscape only
I
couldn't do it in the navigation controller. Instead what I did was
to open a modal view from view A to view B and force a new navigation
controller into this view.
This
is working for me in iOS5+.
You
need to create a category for the navigation controller like this:
UINavigationController+Rotation_IOS.h
#import
<UIKit/UIKit.h>
@interface
UINavigationController (Rotation_IOS)
-
(BOOL)shouldAutorotate;
-
(NSUInteger)supportedInterfaceOrientations;
-
(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
@end
UINavigationController+Rotation_IOS.m
#import
"UINavigationController+Rotation_IOS.h"
@implementation
UINavigationController (Rotation_IOS)
-
(BOOL)shouldAutorotate
{
return
[self.topViewController
shouldAutorotate];
}
-
(NSUInteger)supportedInterfaceOrientations
{
return
[self.topViewController
supportedInterfaceOrientations];
}
-
(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return
[self.topViewController
preferredInterfaceOrientationForPresentation];
}
@end
AppDelegate.m
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return
UIInterfaceOrientationMaskAll;
}
VIEW A Portrait
-
(BOOL)shouldAutorotate
{
return
YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return
UIInterfaceOrientationMaskPortrait
| UIInterfaceOrientationMaskPortraitUpsideDown;
}
-
(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return
UIInterfaceOrientationPortrait;
}
-
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return
(interfaceOrientation == UIInterfaceOrientationPortrait
|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
VIEW A to
VIEW B while Pushing
SignatureViewController
*signatureVC=[[SignatureViewController
alloc]
initWithNibName:@"SignatureViewController"
bundle:Nil];
UINavigationController
*navigationController = [[UINavigationController
alloc]
initWithRootViewController:signatureVC];
[self
presentViewController:navigationController
animated:YES
completion:nil];
VIEW
B Landscape
#pragma
mark -
#pragma
mark InterfaceOrientationMethods
-
(BOOL)shouldAutorotate
{
return
YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return
UIInterfaceOrientationMaskLandscapeRight
| UIInterfaceOrientationMaskLandscapeLeft;
}
-
(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return
UIInterfaceOrientationLandscapeRight;
}
-
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return
(interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
No comments:
Post a Comment