I have the initial view controller that is portrait, and I want the next view controller to only be landscape. The user can't turn the iPhone/iPad to change rotation. Can someone please help me with this?
Any help appreciated.
I think what you want is : shouldAutoRotateToInterfaceOrientation method of UIViewController Class.
This function returns YES if the orientations is supported by your UIView. If you return YES only to the landscape orientation, then the iPhone will automatically be put in that orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
GoodLuck !!!
Perhaps you are looking for UIViewController shouldAutorotateToInterfaceOrientation or some of the other orientation related members.
Related
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.
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);
}
You can use following code in your viewWillAppear method to make your view portrait.
[[UIDevice currentDevice] performSelector:NSSelectorFromString(#"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait];
I have a simple navigation app that has 95% of all views displayed in landscape mode. With the one view that makes sense to only show in Portrait mode i have inserted the following code in:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
The problem is that when the app navigates to the view (from a landscape orientated view) it does not switch the orientation to portrait, only when the device is rotated will it snap into portrait and stay in portrait. Is it possible to force it to load in portrait mode on load of the view?
Thanks in advane
I think you should go through : shouldAutoRotateToInterfaceOrientation method of UIViewController Class.
This function returns YES if the orientations is supported by your UIView. If you return YES only to the portrait orientation, then the iPhone will automatically be put in that orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
I have storyboard project in xcode. Most scene is show in portrait orientation but I want to show one of scene in landscape mode without user rotate the device, always this scene is shown it must be in landscape. This scene has a simple viewcontroller with uiwebview object wich I open a pdf file from url. My idea is show the viewcontroller as a modal viewcontroller.
Anyone known how solve this issue?, yesterday I spend my time searching about this in Internet but I don't find out a solution.
Thank you in advance!
How the scene is actually displayed is not determined by the storyboard but rather the viewcontroller. You need to create an UIViewController subclass and implement - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation to return YES only if the interface orientation is a landscape orientation. You could do it like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
to allow both orientations or replace with
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft
to allow only one direction.
I have application that uses landscape right orientation.
In view controllers I use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
But, If user locks iphone or ipad to portrait orientation, screen is displayed
as portrait, not landscape. Also, in info.plist file I defined only Right Landscape orientation as
supported one.
Try setting the UIInterfaceOrientation key in your Info.plist to UIInterfaceOrientationLandscapeRight. That should force landscape right orientation on launch.
The problem was in function viewDidLoad where another view controller is pushed into navigation stack immediately. If pushing action is delayed then landscape rotation will start and proceed, and also desired view controller will be pushed properly with landscape orientation.
i am having tabBarController.It is having 3 viewControllers.I want to support landscape mode in only one of these viewControlers.and other 2 view controllers in potrait mode.How to achive this.
In the view controller you want to support landscape simply return YES to
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Of course I'm assuming your implementation is creating a view controller for each view
Ya i am having view for each viewController.But i want to support landscape in only one view and rest all in potrait mode.Even i am returning YES in (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
if interfaceOrientation is landsape in view which i want to support and in rext views i am returning NO in this method if interfaceOrientation is landScape mode.