Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone app is in landscape mode, but view's bounds is still portrait

Tags:

uikit

iphone

What's really going on behind the scene when you set the phone's orientation to landscape mode? When I traced out main screen's bounds and any subview's bounds, the width and height is still 320x480, rather than 480x320.

Any idea why?

like image 396
Boon Avatar asked Sep 13 '09 06:09

Boon


People also ask

Why do some apps not rotate on my iPhone?

Some apps don't support rotation, so your screen may not rotate even if Portrait Orientation Lock is turned off.

Can you force an app into landscape mode?

When on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.

Why do some apps not work in landscape mode?

Ensure that you have enabled Auto-rotate for your tablet. To do this, swipe down on the tablet to display the status bar and touch Auto Rotate. Some mobile versions of apps do not support Landscape mode, so they may not be displayable in Landscape mode on the tablet.


3 Answers

Are you checking the bounds property or the frame property? Certain controls, especially UIViews that fill up the screen, appear to maintain the same frame in any orientation; I think that AppKit sets their transform property to rotate their contents.

You will probably find that the bounds property has the value that you expect it most of the time, but that the frame property does not.

like image 159
Leo Avatar answered Oct 03 '22 05:10

Leo


This is a large topic, but I'll add what amounts to 0.02; comments are constrained to changes between portrait and landscape; i.e., not things like upside down, face up, face down, and unknown.

  1. If a view is not listening for orientation changes then the frame and bounds will remain the same regardless of orientation.

  2. If a view has registered to listen for orientation changes then the bounds may change; i.e., in landscape whole screen frame is <320,480> while bounds is <480,320>. This assumes:

    a. you are either using a shouldAutorotateToInterfaceOrientation callback with appropriate YES return values, or

    b. explicitly registering with the notification center to listen to UIDeviceOrientationDidChangeNotification.

  3. Approach 2a will hold true only for views belonging to the app window's root view controller; that is, the view controller whose view was added first. Approach 2b can be used in conjunction with affine transforms and manual bounds changes to get proper orientation layout for views not governed by autorotation.

like image 20
jstevenco Avatar answered Oct 03 '22 06:10

jstevenco


I found that if you are not using an UINavigationController you can get problems with your view not being given the correct view and frame bounds.

I was directly adding views to the UIWindow and had exactly this problem. But when I sandwiched a UINavigationController between the UIWindow and my UIViews the problem went away.

Hope that helps

like image 21
mmopy Avatar answered Oct 03 '22 07:10

mmopy