Reputation: 47
I need a view that can display both in Portrait and landscape.But when I load another view I only want it show in landscape.
I have a view controller A.which can be shown in portrait and landscape.This view controller is create by the App delegate.
When I click a button on the view A.I create a view controller B which I want to display only in landscape.and load the view like [A.view addSubView:B.view].
When I rotate the device the function shouldAutorotateToInterfaceOrientation is called only in
controller A. No matter how I set the function in controller B.It can't be called.
Upvotes: 0
Views: 1775
Reputation: 7279
On your first view, make sure that
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
return Yes;
}
And in your second view set it to
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Update:
Ok, try this...
In your main view controller/app delegate, where the shouldAutorotateToInterfaceOrientation is run every time the device rotates, put a global level variable. something like
.h
@interface NavAppDelegate : NSObject <UIApplicationDelegate> {
Bool *isMain;
}
.m
-(void)viewDidLoad {
isMain = Yes;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
if (isMain) {
return Yes;
} else {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
}
// This bit is where you'll have to adapt it to how you change your views
// but it's a basic idea.
-(void)bitThatDoesTheViewChange:(viewController *) controller {
isMain = No;
*viewController = controller;
[viewController release];
isMain = Yes;
}
Upvotes: 5