PDA

View Full Version : How to keep a screen landscape




arnieterm
Feb 17, 2009, 09:14 AM
Instead of designing [using IB or through code] a screen in landscape mode, how can we make a screen to always look in landscape mode even if the user rotates the iphone.
My problem is that with a touch on a button I have to show a screen in landscape and that screen needs to remain in landscape even if the iphone is rotated to left or right. There is another button on second screen that when touched by user will again take to first screen and in that case the screen needs to again come in the state in which it is originally.

With Regards
Parvez Qureshi



dejo
Feb 17, 2009, 09:33 AM
The answer lies in the shouldAutorotateToInterfaceOrientation: method of your view controller.

mars.tsang
Feb 17, 2009, 01:00 PM
The answer lies in the shouldAutorotateToInterfaceOrientation: method of your view controller.

first ,you should disable the autoratate ,that means you should Return false in the shouldAutorotateToInterfaceOrientation: method of your view controlle.
then ,you could use code like
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];

[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft animated:NO];

[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait animated:NO];

to make your iphone in landscape mode or back to portrait mode.

dejo
Feb 17, 2009, 05:51 PM
first ,you should disable the autoratate ,that means you should Return false in the shouldAutorotateToInterfaceOrientation: method of your view controlle.
then ,you could use code like
[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];

[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationLandscapeLeft animated:NO];

[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait animated:NO];

to make your iphone in landscape mode or back to portrait mode.
That's only going to affect the statusBarOrientation and not anything else in the UI. There's a little more to what the OP wants, I believe.

arnieterm, I'd suggest you stop by my iPhone Programming Tutorial - Landscape-Only View-Based Application (http://dejoware.com/blogpages/files/iphone_programming_landscape_view_tutorial.html) blog posting.

mars.tsang
Feb 18, 2009, 04:01 AM
That's only going to affect the statusBarOrientation and not anything else in the UI. There's a little more to what the OP wants, I believe.

arnieterm, I'd suggest you stop by my iPhone Programming Tutorial - Landscape-Only View-Based Application (http://dejoware.com/blogpages/files/iphone_programming_landscape_view_tutorial.html) blog posting.

That's will also rotate the other UI element of the screen .
And i think OP's app shouldn't be landscape only :-)