I am working on app and developing on Xcode 5. App is for iPad from iOS 5 to iOS 7 support. I restrict app to Landscape Left and Right, which is defined in plist and Project settings.
Also defined by code
in App delegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskLandscape;
}
In Classes
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}
But what happened, It works fine on iOS 7 and iOS 6 but it always rotated to iOS 5 when device move portrait. I am stuck here how to restrict this only on Landscape. Kindly help me on this. Thanks in advance.
U can lock the orientation change.
- (BOOL)shouldAutorotate
{
if (autoRotate) {
return YES;
}
else
{
return NO;
}
}
Try with following code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||interfaceOrientation == UIInterfaceOrientationLandscapeRight)
return YES;
else
return NO;
}
By using above code is device is not rotate with portrait orientation.
Related
This question already has an answer here:
Force Landscape ViewController in iOS 7
(1 answer)
Closed 8 years ago.
how can i lock landscape in ios., i was tried many method but not worked, Can any one share latest code for lock landscape.
-(void) portraitLock {
BSEAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
appDelegate.screenIsPortraitOnly = true;
}
- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortrait;
}
+(BOOL)shouldAutorotate
{
return NO;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
As of IOS6 shouldAutorotateToInterfaceOrientation was depreciated in place of willRotateToInterfaceOrientation or didRotateFromInterfaceOrientation
You should also change the views orientation to Landscape in the Attributes Inspector.
If your entire app is to be displayed in Landscape you can also add UISupportedInterfaceOptions to your apps info.plist and specify Landscape.
Check above Image
check only Portrait mode.,,,,
i am working on a app where I am required to show "MPMoviePlayerController" in landscape mode and portrait mode. But My whole app is required to support Portrait mode only. That is no landscape mode for any view other than for the "MPMoviePlayerController".
I tried few things given over stack overflow. Nothing worked in my case. Feels Stuck in the middle. But I have seen some of the app supporting suck kind of requirements.
I have to implement it for both iOS 6, 7
In my app am using "XCDYouTubeVideoPlayerViewController" for playing videos(playing the youtube videos)
Please Help
I had the same issue, and the following solved the problem:
First you need to allow the Landscape mode either, by checking the checkboxes at Target / General / Deployment Info / Device orientation, and then you have to disable Landscape orientation by code at every ViewController you use in your app.
#pragma mark - Set Supported Device Orientation
//For iOS6
- (BOOL)shouldAutorotate {
return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
//For iOS4 and iOS5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
But don't disable landscape orientation for the XCYoutubeVideoPlayerViewController, so at fullscreen it can rotate to landscape.
I have another solution for this, It will work for all MPMoviePlayerController, below is my code
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)windowx
{
if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]] ||
[[self.window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(#"MPInlineVideoFullscreenViewController")])
{
if ([self.window.rootViewController presentedViewController].isBeingDismissed)
{
return UIInterfaceOrientationMaskPortrait;
}
else
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
What we basically do here is we enable Landscape orientation for all MPMoviePlayerController classes which are actually MPInlineVideoFullscreenViewController when you present it for fullscreen.
Hope this helps
I want to support the autorotation in iOS 6 and 7. In my project I have a UITabBar with 4 ViewControllers. Only one ViewController of them should support the autorotaion to Portrait and Landscape. The other views should support only the Portrait style.
I hope you have an idea how to implement this function. shouldautorotatetointerfaceorientation doesn't work in iOS 7 :(
I added a UITabBarConntroller to control the autorotation
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (self.selectedIndex == 1)
return (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationPortrait);
else
return UIInterfaceOrientationMaskPortrait;
}
Maybe there is a way to change the Orientation manual when the View with the index 1 did disappear??
I hope you have a solution!
Set the orientations settings like this:
In UITabBarController:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// You do not need this method if you are not supporting earlier iOS Versions
return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
-(NSUInteger)supportedInterfaceOrientations
{
if (self.selectedViewController)
return [self.selectedViewController supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate
{
return YES;
}
Open project
Go to the General tab
Under orientation options check all checkbox orientation that you need to support
Go to the implementation of first view controller and add this code:
- (BOOL)shouldAutorotate
{
return YES;
}
Also for supporting iOS 6 implement method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationMaskAll);
}
Go to all other view controllers that are represented your tabs and set:
- (BOOL)shouldAutorotate
{
return NO;
}
Also for supporting iOS 6 implement method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Check this link as well
I am using this code to lock the landscape mode for my iOS application.
#pragma mark Orientation handling
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
}
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown);
}
It is working fine in iPhone but it is not working correctly in iPad. It does not lock the landscape mode.
Need some guidance on this.
This code is incorrect:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationMaskAllButUpsideDown);
}
A UIInterfaceOrientation is not a UIInterfaceOrientationMask. Try something like this instead:
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
That being said, if you are trying to lock your application into landscape mode, there are multiple other issues here — for instance, your supportedInterfaceOrientations lists only portrait modes, not landscape!
Ideally just set it in the summary tab as the comment says. If you really want to do this in code, this is only available in whatever you set as the rootViewController in your AppDelegate class.
In iOS 6 I use:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
If you have a NavigationController you can add the method to a Category.
I use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight;
}
I have released an app, and for some reason only some people are having an orientation issue with the app. Namely that it is opening in Portrait mode, and is un-rotatable from here where as the app is set up to only be allowed in LandscapeLeft and LandscapeRight. Most people aren't having this issue, however I've received a few complaints recently through our support page.
People with the issue seem to be on iOs 5.1 and iPad gen 1s, which is the lowest OS my app supports.
Here is the code handling the rotation:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
return YES;
}
else
{
return NO;
}
}
And here is the .plist
http://tinypic.com/r/nnvfhz/6
Any suggestions would be great.
In iOS5, you must override the shouldAutorotateToInterfaceOrientation: method:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// support all interface orientations
return YES;
}
This method was deprecated as of iOS 6, for which you should use these:
- (BOOL)shouldAutorotate {
// return whether autorotation is supported
return TRUE;
}
- (NSUInteger)supportedInterfaceOrientations {
// return the mask that represents the supported interface orientations
return UIInterfaceOrientationMaskAll;
}
Finally, I'll mention this method, since it's often applicable:
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
// set the preferred orientation of view controllers presented in full-screen
return UIInterfaceOrientationLandscapeRight;
}