nworksdev
nworksdev

Reputation: 235

Switching from Landscape View to Portrait View on iOS

I have two views in my application. One (by default) is Landscape. When the user clicks a certain menu, i need a Portrait view to appear.

I have all the code in place and i'm trying to use this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

      return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

But the app still displays the next view in Landscape. I can't figure this out. Any help will be great.

Upvotes: 1

Views: 396

Answers (2)

Rahul Patel
Rahul Patel

Reputation: 5886

You can use following code in your viewWillAppear method to make your view portrait.

 [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait];

Upvotes: 0

amit soni
amit soni

Reputation: 2163

You can not do it using navigation controller but if you are presenting your view then it  is possible to do that and make sure when you are presenting your view animation should be NO.
It works for me very well.

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

Upvotes: 1

Related Questions