How do I get my iPhone app to start in Landscape mode? - iphone

My app is fixed to landscape mode, yet during viewDidLoad() and even viewWillAppear(), the following portrait dimensions still return:
self.view.bounds.size.width = 320.00
self.view.bounds.size.height = 480.00
It's not until viewDidAppear() that the actual landscape dimensions result.
self.view.bounds.size.width = 480.00
self.view.bounds.size.height = 320.00
I find this weird.
Why does this happen!? and how can I fix this?

In your app's info.plist file, specify the key:
UISupportedInterfaceOrientations
with values for landscape left and right:
EDIT:
The raw plist code should look like this:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Edit 2
You also need this key which determines the initial orientation of the status bar:
<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationLandscapeRight</string>
Further, you need to make sure that ALL of your view controllers (tabbar, navbar, regular view-controllers) implement
shouldAutorotateToInterfaceOrientation
and return a Landscape (left or right) value.
Here is an Apple docs article on the subject:
Technical Note TN2244
And finally, here are some other SO posts on this topic:
post 1 and post 2.

Related

iPhone application landscape mode doesn't work

Currently I have only portrait mode in iPhone application. I would like to permit landscape mode for one controller in application but unfortunately I'm not able to make it work.
I have these settings in my plist file:
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
</array>
And I implemented these methods in my controller:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
-(BOOL)shouldAutorotate
{
return YES;
}
I use navigation controller in the app so I realize that it might be the problem. I subclassed the UINavigationController and implemented again shouldAutorotateToInterfaceOrientation, supportedInterfaceOrientations and shouldAutorotate in the same way as above. Of course for I use subclassed navigation controller to show the controller which should have ability to rotate. I also tried to overwrite the methods of navigation controller by category but it also doesn't work.
I don't work on the application from the beginning, I inherited the codes. If there is some possibility how to restrict landscape globally it might be my case. For testing I use iPhone 6.0 simulator but my deployment target is 5.0. I appreciate any tips / help.
iOS6 also requires that you set a rootViewController for your window rather than adding the controller's view as a subview.
If you are doing something like this:
[window addSubview:someController.view];
then you can try changing it to this:
[window setRootViewController:someController];
Also look at this link. For ios6, Apple introduced these two methods :
supportedInter
faceOrientations:
shouldAutorotate
Hope it helps.
Shumais Ul Haq
Try this on Controller youwant to give landscape orientation
// override to allow orientations other than the default portrait orientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation); // support only landscape
}
Go to target window.
Click on Summary tab.
iPhone/iPad Deployment info -> Set the supported interface orientations for iPhone & iPad as per your requirement. See following image for more reference.

How to make my view rotatable with the device orientation?

i am working on the Remote Desktop protocol in this i facing a lot of Problem.
You guys are really good and help me in many critical situation .
My problem Goes like this:-
If i click on any button to connect to RDP after that if i wants to rotate the Device it is not happing
i made shouldAutorotateToInterfaceOrientation Yes ,still the same
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
In the info.plist file under the array "Supported interface orientations", you could add this:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string> UIInterfaceOrientationPortraitUpsideDown</string>
</array>
Hope this helps!

How to support only portrait mode on an iPhone app

I have a strange problem in an iPhone app I'm developing. I want my app to support ONLY portrait mode, but for some reason I can't do it (device & simulator).
To support only portrait mode I did as follow:
In the TARGET summary section on Xcode, I chose only portrait.
All my ViewControllers implements shouldAutorotateToInterfaceOrientation
But as I said it won't work, and the strange result is that the app support ALL the orientations (portrait, upside down, landscape left, landscape right).
Any ideas?
this how I implement shouldAutorotateToInterfaceOrientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
NSLog(#"Checking orientation %d", interfaceOrientation);
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
I notice just now that when I rotate the phone I get this message:
"Two-stage rotation animation is deprecated. This application should
use the smoother single-stage animation."
What does it means?
On the Target Summary choose portrait only.
Go to info.plist file. Right Click open it as source code. And look for this line. For me in iPad its like this:
<key>UISupportedInterfaceOrientations~ipad</key>
Delete all other orientation and keep the only one which you need..Like this :
<array>
<string> UIInterfaceOrientationPortrait </string>
</array>
It is possible to have multiple ViewControllers on the screen. The UITabBarController is itself a UIViewController, and it only passes shouldAutorotateToInterfaceOrientation: requests to the viewControllers within if it chooses. The default implementation does this, but if you subclass it, the code XCode generates (as of iOS 5.1) does not.
check your plist and make sure the key there is set correctly.

Application doesn't oriented

My application doesn't oriented even if I use
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}
the only thing I do is to hide the lower tab bar using
SearchScreen.hidesBottomBarWhenPushed = YES ;
Any idea how to fix that
Some ideas:
Are the "Supported Device Orientations" set properply?
Maybe a parent ViewController is not allowing interface orientation?
If testing on a device: Is it "orientation locked"?
Setting 'Supported Device Orientations' inside Info.plist:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
Please write
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
return YES;
}
in all your tab bar's root view controller.
Can you tell me your which one is root view controller that tab view controller??

UIwebview content is not loading properly

I got a pretty weird thing, am using UIWebView in one of my apps, but while the device is being rotated to landscape mode, the UIWebView content is not loading properly.
I can see the UIWebView size as proper but the content is somehow dangling.
For the case, I checked safari in iTouch, but for them its working pretty fine.
I dunno where is the issue. I am posting it after a brief search but could not get any help either.
If any you guys know how to fix this, it will be really helpful.
Cheers,
Manoj
If your application supports all 4 orientation then in info.plist create a key for Supported interface orientations.
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
//Also you can use this method
}