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
Related
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;
(Using Storyboard)
I'm trying to make one of my ViewController Subclasses support more than just portrait view.
I've added in
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationPortrait));
}
but it doesn't seem to do anything. I've got all orientations except upsidedown supported in my plist, and added the shouldautorotate to allow only portrait in the viewcontrollers that I want.
The method you're looking for in ios6 is - (NSUInteger)supportedInterfaceOrientations
This essentially replaced shouldAutorotate. Use it in conjunction with shouldAutorotate.
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)
);
}
I have an iPad game that I only want to see in landscape view. I have selected the landscape view from the target's summary and have the code
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return YES;
}
in my first viewcontroller which is added to a navController. But the only effect that I can see by changing the target's orientations is not how it can be rotated but rather what direction it is first loaded in. Does anyone have any ideas? Thanks!
Try this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
i have use this code but it is Private API ,apple also reject!
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
if i rotate my device in Landscape then open my Application it will present as Portrait mode, i need to rotate my device to another orientation then it will update.
how to update it to correct orientation when call UIViewController?
You should use the follow code at your UIViewController class:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
if u need to update orientation at runtime then u have to return other constant
return (interfaceOrientation == UIInterfaceOrientationPortrait);