IPhone app is in landscape mode, but viewing borders is still a portrait

What really happens behind the scenes when you set the phone's orientation in landscape mode? When I tracked the borders of the main screen and any borders of sub-images, the width and height are still 320x480, not 480x320.

Any idea why?

+6
iphone uikit
source share
6 answers

A problem has been discovered - the reason why the borders remain unchanged after the rotation, because the only thing that affected after the rotation is the view transformation property.

A quick trace of the view transform gives me the following:

2012-01-31 12:19:02.114 TestScollviewRotation[9834:207] orientation: UIDeviceOrientationPortrait 2012-01-31 12:19:02.116 TestScollviewRotation[9834:207] 0.000000 -1.000000 1.000000 0.000000 2012-01-31 12:21:41.898 TestScollviewRotation[9834:207] orientation: UIDeviceOrientationPortraitUpsideDown 2012-01-31 12:21:41.898 TestScollviewRotation[9834:207] 0.000000 1.000000 -1.000000 0.000000 2012-01-31 12:21:58.780 TestScollviewRotation[9834:207] orientation: UIDeviceOrientationLandscapeRight 2012-01-31 12:21:58.780 TestScollviewRotation[9834:207] 1.000000 0.000000 -0.000000 1.000000 2012-01-31 12:19:03.181 TestScollviewRotation[9834:207] orientation: UIDeviceOrientationLandscapeLeft 2012-01-31 12:19:03.181 TestScollviewRotation[9834:207] 1.000000 0.000000 -0.000000 1.000000 
0
source share

Are you checking the bounds property or the frame property? Some controls, especially UIViews that fill the screen, seem to support the same frame in any orientation; I think AppKit sets its transform property to rotate their contents.

You will probably find that the bounds property has the value that you would expect in most cases, but the frame property does not matter.

+1
source share

This is a big topic, but I will add that is 0.02; comments are limited to changes between portrait and landscape; that is, things like upside down, face up, face down and unknown.

  • If the view does not listen for orientation changes, then the frame and borders will remain unchanged regardless of orientation.

  • If a view is registered to listen for orientation changes, the changes can change; that is, in the landscape scale of the entire screen is <320,480>, while the boundaries are <480,320>. This implies:

    but. you either use shouldAutorotateToInterfaceOrientation callback with the corresponding return values โ€‹โ€‹YES, or

    b. Explicit registration in the notification center to listen to UIDeviceOrientationDidChangeNotification.

  • Approach 2a will be valid only for views belonging to the application window root view controller; that is, a view controller whose view was added first. Approach 2b can be used in conjunction with affine transforms and manual boundary changes to get the correct orientation for representations not controlled by autorotation.

+1
source share

I found that if you do not use the UINavigationController, you can get problems with your view without getting the correct view frames and frames.

I directly added views to UIWindow and had exactly this problem. But when I launched the UINavigationController between UIWindow and my UIViews, the problem disappeared.

Hope that helps

+1
source share

Yes, the frame and borders remain unchanged, you should check the ViewOontentler property of the ViewController interface and handle the width and height accordingly, if your layout depends on them.

0
source share

I have the same problem with the iPad app at the moment.

I "solved" it by requesting interfaceOrientation views, and if it is either UIDeviceOrientationPortrait or UIDeviceOrientationPortraitUpsideDown , then I manually set my sublayer frame in the view (which is a CAGradientLayer ).

0
source share

All Articles