iPhone locked Portrait, iPad locked Landscape - iphone

I'm trying to convert an iPhone app to iPad. The tricky things is that the iPhone app has to be locked to portrait view and the iPad app has to be locked to landscape view. I'm kind-of a noob at interface builder so I'm a little lost.
Any help is greatly appreciated. Thanks!

You need to override shouldAutorotateToInterfaceOrientation. A good place to put this is in the app delegate.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad &&
UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
return YES;
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone &&
UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
return YES;
}
return NO;
}
I'm not sure, but this may also support the phone being upside-down, which is a HIG no no. You might want to use interfaceOrientation == UIInterfaceOrientationPortrait instead for the phone.

You should have two nibs and load them separately depending on which device your application determines it is running on: one for the iPad and one for the iPhone. You can then set the orientation easily. NB: The iPad app should support all orientations variants (ie. if you support portrait, support portrait upside-down) and will most likely get rejected by Apple unless you have a compelling reason as to why it shouldn't.

Related

rotate my iphone app in ipad when rotate option is enabled

I want to rotate my iphone application in ipad if I rotate the ipad
what I use in my code is :
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
return (orientation == UIInterfaceOrientationMaskAll);
}
and I check both portrait and landscape:
and the plist file:
my application device family is only iphone, and appears as an iphone in ipad device
But it doesn't rotate, please correct my code above, thank you
you ask it ? ;
if ([[UIDevice currentDevice] userInterfaceIdiom]==UIUserInterfaceIdiomPhone) {
}
Put it into the code if try again.
In the .plist file you only specify your startup orientations. After that every view controller can implement shouldAutorotateToInterfaceOrientation: in which the view controller is "asked" if a rotation to another orientation is acceptable. In the standard template for iPad apps this always returns YES and thus allows all orientations. In your case you might only return YES when the given orientation is UIInterfaceOrientationLandscapeLeft, although you should have a look if you can support both landscape orientations as Apple human interface guidelines strongly suggest to at least support both landscape orientations if one is supported.
Note that every view controller in your app has to specify its own orientations as it may make sense to have some views more restricted than others.
For further information on this have a look at:
Supporting orrientations for iPad apps: http://developer.apple.com/library/ios/#qa/qa1689/_index.html
Why won't my UIViewController rotate with the device: http://developer.apple.com/library/ios/#qa/qa1688/_index.html
UIViewController class reference: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

iPhone locking rotation to portrait view

I know this has been asked before and I actually searched through the questions to make sure I was doing things correctly. My app needs to maintain portrait orientation so I want to disable it from rotating into landscape.
In the summary I have supported device orientations of portrait and upside down only.
In viewcontroller I have:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
I have 6 other viewcontrollers, in each of them I have the following:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
But when I test the app on my provisioned iPhone, it rotates. Grrrr. What am I doing wrong?
Thanks
It's the same in the simulator.

Locking the orientation in an iPad app (plist or UIViewController?)

I'd like the app to work like it would be as if I locked the orientation manually. I'm trying to find how I can lock the orientation for an app. In the info.plist, I have this setting:
Supported interface orientations (iPad)
Item 0 Landscape (right home button)
Item 1 Landscape (left home button)
I thought that would be enough to keep my viewControllers from staying in landscape mode and not portrait. But it does not. Do I need to do
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
in ALL my viewControllers? Thanks!
All though implementing shouldAutorotateToInterfaceOrientation in all your view controllers will work, it is probably not the fastest or most practical way of doing what you are trying to accomplish.
If any of your view controllers in your hierarchy do not conform to the orientation change, then iOS will stop trying to rotate them. What this means is that only your root view controller needs to have implemented shouldAutorotateToInterfaceOrientation with only landscape orientations. Each view controller pushed or added will conform to that function.
I have had to do this in several of my apps and it was required for several reasons.
In the end and after a lot of testing, we determined that the condition has to be set on the info.plist AND on every viewController.
So make sure it is set on the plist and that every shouldAutorotateToInterfaceOrientationonly returns yes for the allowed orientation.
This is because the plist will help you with allowed LAUNCH orientations, but your app could still rotate afterwards, specially when using modal views.
You can download one of my free apps that does thins on iPad: http://itunes.apple.com/mx/app/hoteles-city/id471505865?mt=8
Yes you do.
I have a different solution however. In every UIViewController, I use:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
} else {
return NO;
}
}

how to lock/unlock orientation lock of iphone programmatically?

we know that these simple steps to lock/unlock the orientation of your iPhone 3G:
From any screen, double-tap the home button
Scroll as far left as you can on the multitasking dock
The first symbol to the left will be a circular arrow
Select this to either lock or unlock the orientation of your iPhone 3G
But how we can do this programatically ?
Are you asking if you can do this for your app or lock the orientation for the device itself? Seems to me you're asking for the latter and I would have to ask why you want to do that. It's not possible to lock the orientation for the device, because that way it would be locked in portrait mode for other apps as well.
You can however only support the orientations you want yourself. A lot of apps only support portrait mode and games generally support landscape only.
You can set the supported device orientations of your app in XCode. At the viewcontroller.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Assuming you want to support both landscape orientations.
You can't do it programmatically -- it would be plain wrong for an app to change a setting that affects everything else.
In your own app, you can restrict the supported orientations by setting UISupportedInterfaceOrientations in your info.plist (see doc here). You can also restrict orientation per view through shouldAutorotateToInterfaceOrientation (see doc here)

UI autorotation works only on some devices?

I'm having quite interesting (but very annoying) problem with (not only) UI autorotation. I'm working on the app which contains tabbar controller with couple of navigation controllers as tab items. One of those controllers allows for autorotation to landscape mode.
Interesting is that it perfectly works in Simulator as well as on my own device, but it's not working on other testing devices. All devices are the same - iPhone 3G 16 GB, OS version 3.1.3.
When I'm looking for a log messages which report orientation change events in console, I can find it again only on my device, but not on other devices, so it seems that other devices do not report orientation change at all. Which is very unlikely on the other hand, because other apps are working normally... Also some other features which are working on my phone are not working on other devices too (touch events handling in tableview for instance).
I've never seen something like this and cannot find any reason why the hell it should not work on all devices the same way! So the question is - am I mad or what?
I use subclass of UITabBarViewController with overriden method
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation {
BOOL shouldRotate = (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft);
NSLog(#"Should rotate: %d", shouldRotate);
return shouldRotate;
}
Then I handle orientation change animation in respective methods (willRotate..., willAnimateRotation...). But as I said - it works fine on my device, but on other devices the shouldAutorotateToInterfaceOrientation: method gets never called. Weird!
Please give me some hint before I'll end in a madhouse. Thanks for any tip.

Categories