Only statusbar is rotating to Landscape (iPhone) - iphone

In One of my Viewcontroller that supports only Portrait orientation. On my
device when rotate the status bar is rotating to landscape
orientation. The rest of the view remains in Portrait mode. I want to prevent the roation of statusbar. This
problem is happening only in IOS7
// Overridden function to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
// iPhone: support only upright portrait
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
else
{
// iPad: any orientation is OK
return YES;
}
}
// For iOS6.0 Rotate
- (BOOL)shouldAutorotate
{
return NO;
}

Use this method to keep it in Portrait view :
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;

Related

Supported orientation madness

I know this is the most commonly asked question and trust me I have tried every kind of combination to make this happen and went through most posts here on stack overflow.
I have a UINavigationController called v1ViewController and what I am trying to do is when it is shown to the user I just want it to either show in portrait or portrait-up-side-down modes, no landscape even if the user rotates the device in landscape it shouldn't do anything.
NOTE: I did highlight all options in Xcode for supported interface orientations as in one of my other view controller I need to show user something in both landscape and portrait modes but for this UINav Conrtoller I want it to just remain in portrait modes.
The code I have for iOS 5.0 work just fine without a problem.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
return YES;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return YES;
}
else
{
return NO;
}
}
the headache I have is with iOS 6. No matter what I try and do it still lets the user rotate the bloody thing in landscape (see code and screenshots)
// *********************
// iPhone 5 orientation support
// *********************
- (BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait)
{
return YES;
}
else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
return YES;
}
else
{
return NO;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
You need to ensure you override the base UINavigationController and assign a custom class to it(not just the viewController that is the subview for the UINavController..ie the view contained below the navigationBar). Inside the UINavigationController, return NO on shouldAutoRotate.

Landscape app for ipad doesn't have home screen landscape

I am creating landscape app for iPad, but when I run the application I found the home screen displays as portrait. How can I solve it?
Select the target, in that select only Landscape Left and Landscape Right option in "Supported Device Orientations. And also in your roo view controller set
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
return YES;
return NO;
}
Ensure your app only supports landscape orientations in your Project Settings (unselect 'Portrait' and 'Upside Down'):
View Controllers that support landscape should say they do, too:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
add this methord
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
NSLog(#"Changed interface orientation");
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
);
}

How To Restrict Changing Into Landscape Iphone?

I do have five view controllers, and i am navigating from first view Controller to end view Controller (fifth view controller)
In middle i do third view i need to do orientation. for landscape and potrait mode.
and from there it need to be potrait mode only.
I added this delegate method for orientation in fouth viewController . but its not effecting
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
//Support orientation for Portrait
return (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation==UIInterfaceOrientationPortrait );
}
I think your changing orientation in your first view.Open your third view and write this method then change whatever you want...i think you should write this in all of the view expect third view...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
Now in your third view write your code....
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Overriden to allow any orientation.
//Support orientation for Portrait
return NO;
}
just do.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (interfaceOrientation == UIInterfaceOrientationLandscape)
return NO;
else
return YES;
}

Allow only LeftLandscape and RightLandscape orientation

How can I made my app to allow only the landscape orientation but both (left and right)?
so if I rotate 180° the app will be rotate but if I rotate in portrait the app doesn't rotate?
thanks
Try adding this to your UIViewController:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
You can learn more about this here: UIViewController class reference

How to disable any autorotation?

I am trying to code for calling Landscape screen from Portrait screen.
When current screen orientation is Landscape, it would be doesn't allow any autorotation.
I've tried the following code :
// Override to allow orientations other than the default portrait orientation.
/*- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}*/
- (void)viewDidLoad {
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
landscapeTransform = CGAffineTransformTranslate(landscapeTransform, +90.0, +90.0);
[self.view setTransform:landscapeTransform];
}
But above code is allowing UIInterfaceOrientationLandscapeRight.
How to disable any autorotation ?
Thanks in advance.
Do you want start your application in the landscape mode or not?
In all case you must override the shouldAutorotateToInterfaceOrientation method.
But if you want start your application in the Portrait mode and then go to the Landscape mode you can add a static boolean to know if you must stay in the landspace mode or not.
You code must look something like that:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(isInPortraitMode) {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
} else {
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
isInPortraitMode = YES;
}
return YES;
}
}
- (void)viewDidLoad {
isInPortraitMode = NO;
//...
}