I set the initial orientation of the app to UIInterfaceOrientationLandscapeRight, but when I open the app with the physical orientation of UIInterfaceOrientationLandscapeLeft, it will show the interface of UIInterfaceOrientationLandscapeRight first, then rotate to the UIInterfaceOrientationLandscapeLeft orientation.
How to make it open with the same orientation as the device?
You have to instruct your UIViewController instances on which interface orientations are supported by implementing "shouldAutorotateToInterfaceOrientation" as follows:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
return YES;
} else {
return NO;
}
}
Related
The view right after the launch screen is required to be presented in the device's orientation but should not autorotate to other orientations once it is presented. I used this code :
- (BOOL)shouldAutorotate {
[super shouldAutorotate];
return YES;
}
-(UIInterfaceOrientationMask) supportedInterfaceOrientations {
[super supportedInterfaceOrientations];
return UIInterfaceOrientationMaskAll;
}
This works well for iPad but in iPhone, setting NO for shouldAutorotate results in Portrait only. Is this normal behaviour? If so how can all orientations be supported without autorotation in iPhone, for a particular view controller only?
You need to detect what orientation the device is in when you start up:
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
Convert that to an interface orientation:
switch (orientation) {
case UIDeviceOrientationLandscapeRight:
return UIInterfaceOrientationLandscapeLeft;
default:
return UIInterfaceOrientationLandscapeRight;
}
Now store it somewhere for global access and return that:
- (UIInterfaceOrientationMask) supportedInterfaceOrientations {
return globalOrientation;
}
I am develop a IOS Application, I use the following code for lock the orientation of App.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
If the orientation is UIInterfaceOrientationPortrait When start the App. It will lock the orientation to UIInterfaceOrientationPortrait.
But the view still show Landscape , when start the App in Landscape.
How to set the Orientation of App to UIDeviceOrientationIsPortrait for App start whether the phone is Landscape or 'Portrait`?
If you need to lock the whole app to Portrait then go to TARGETS -> General Tab -> Deployment Info
This will lock the whole app to Portrait Mode
If you only need one orientation for the entire app then go to targets, General, and deployment info. Then check portrait.
I use the following code for setting Orientation to Portrait.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated] ;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//set the orientation is Portrait when the App start.
if ([[UIDevice currentDevice] respondsToSelector:#selector(setOrientation:)]) {
objc_msgSend([UIDevice currentDevice], #selector(setOrientation:), UIInterfaceOrientationPortrait );
}
}
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
My app works only in Landscape.
Thus I set the Initial Orientation and Supported Orientation at LandScape Home Right.
However, initial launch orientation always becomes Portrait.
After navigating to next page and return, the orientation is correct.
This might be the similar question to the following, In IOS 6 on iPad, initial rotation is always portrait, after that it always rotates correctly
But the solution there is not working as the 'handleRotationFor' gives warning:
instanceMethod -handleRotationFor is not found (return type defaults to 'id')
How should I fix this error?
Please help
project Targets --> click on "Summary" tab and choose your Orientation in "Supported interfaces Orientations"
In Xcode in the files pane click on your project and then select target from right pane. Then in Summary tab see supported orientations. Only select Landscape right. Also you can implement
-(NSUInteger)supportedInterfaceOrientation {
return UIInterfaceOrientationMaskLandscapeRight;
}
in your app delegate
In Xcode under summary tab make sure portrait and upside down are not pressed down. Also Add these three functions.
// *********************
// ios6 orientation support
// *********************
- (BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
return NO;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return NO;
}
else
{
return YES;
}
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return NO;
}
else
{
return YES;
}
}
Check the supported orientations in the info.plist of the app. Check and set orientations in the nib file as well.
You can check orientations by using [[UIDevice currentDevice] orientation]
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;
}