I have created a project, with both portrait and landscape orientation. What should I do to keep only a few screens rotatable?
Play with:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
If you have a UITabBarController, then you you will have problems, because either all rotate or none. Although I think there are some workarounds.
Related
my app has been working fine until I've tried making some changes using the ios 6 SDK
The app runs in portrait mode 99% of the time. This has been constrained by only allowing portait mode to be available in the info.plist
There is one view controller which needs to be shown in landscape mode. This is achieved "manually" by simply rotating the view by 90 degrees, like so:
self.view.transform = CGAffineTransformMakeRotation(3.14159/2);
This still works fine in iOS 6.
However, this view controller has some text fields. When the user taps one it shows the keyboard. Since I've only rotated the view (and not actually changed the orientation of the device), the keyboard comes out in portrait mode, which is no good.
In previous versions of iOS, I set the orientation of the status bar to be landscape, and as a byproduct, this would set the keyboard to be landscape as well, like this:
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];
However, this has stopped working for iOS 6.
I have read a million stack overflows trying to get this to work, but still have no luck.
Changing the keyboard orientation and transform is an difficult part and not a good solution(especially when it changes status bar orientations).
Better solutions is to allow application to support all orientations.
Implement the Orientation delegates inside your ViewControllers asper the rotation support.
For Supporting only Landscape
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationLandscapeRight ;
}
- (BOOL)shouldAutorotate
{
return NO;
}
For Supporting only Portrait
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
I am having a problem with device orientation. I have an iPhone app that has some views, all of them should not rotate except one. So I take a look inside Info.plist; I select two device orientations, portrait and lanscape, and in the views I dont want to rotate so I put this.
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
but all the views rotate. Even with these lines in them. If change Info.plist to support no portrait. It works ok, just the view that I want to rotate, I put
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
And it does not work. I use iOS 6. Also tried
- (NSUInteger)supportedInterfaceOrientations
- (BOOL)shouldAutorotate
Try specifying exactly the orientations you would like the view to rotate to. For instance, if you want portrait only use this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
For rotating to all views, you can still use YES, although this will allow it to rotate to the upside down view which isn't always desired. To get both landscape orientations and right side up portrait, use this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
I want to make a landscape iPad app.
I did below 3 things. the simulator orientation is landscape which is correct. However, the content is 90 degrees wrong, but they are right in the storyboard view, landscape. Is there anything I need to check?
I set my storyboard as landscape.
May project I already set "supported interface orientations" = landscape
Also used this code in view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
return YES;
else
return NO;
}
Make sure "Initial interface orientation" set in your Info.plist as well.
Supported Interface Orientations is one thing. It didn't work for me until I did the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
You have to use the following code on ALL of your viewcontrollers
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight)
}
In my App, I have a tabbarController and 5 view controllers managed by it.
I only want one UIView rotate to landscape and make the tabbar invisible when rotate to landscape. In current condition, all my views autorotate themselves which is not what I expect.
The code of UIView which I dont want it rotate is:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationLandscapeLeft) {
// stop the rotation, keep it as portrait orientation
// from app document, it says for UITabbarController, rootview which is uitabbarcontroller and views managed by it should all agree on the same orientation otherwise they wont rotate.
// how can i do this?
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
I have a very strange problem that I am as yet unable to diagnose.
In my iOS app (it's a universal binary), when I run on iPad 4.3, the orientation at launch is inconsistent.
The app delegate adds a splash screen (UIViewController) to the main window, then removes it and adds the app's primary view. It is this primary view which is the issue - approximately half of the time, it loads up correctly in landscape orientation, the other half it loads the view in portrait (though both the status bar and keyboard are correctly in landscape).
I'm at a bit of a loss as to why the orientation at launch is changing, when I am making no changes to the code or the simulator/device orientation.
I have UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight set as the only supported orientations for iPad in the Info.plist and every view controller is using the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// The device is an iPad running iPhone 3.2 or later.
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
} else {
// The device is an iPhone or iPod touch.
if (interfaceOrientation == UIInterfaceOrientationPortrait) {
return YES;
}
}
return NO;
}
Can anyone help me out with this??
Cheers,
Olly
If the status bar and keyboard are always in landscape then the problem should not be in shouldAuto... method. It might be in viewDidLoad. Also, try the following: in project-info.plist, set "Initial interface orientation" as landscape left/right, "clean" the project and run.