iPhone Viewport Height Too Large in Landscape Mode

Set view as percentage of width in portrait and percentage of height in landscape, in interface builder using autolayout

The trick is to add two sets of proportional width and height constraints...

First:

  • centerX
  • centerY
  • 1:1 aspect ratio

Then:

  • width <= 0.7 @1000
  • width = 0.7 @750
  • height <= 0.7 @1000
  • height = 0.7 @750

So our constraints are saying:

  • try to make width and height each at 70% -- Priority: 750 (High, but not Required)
  • but keep the image view at 1:1 ratio -- Priority: 1000 (Required)
  • and neither width nor height can be greater than 70% -- Priority: 1000 (Required)

Here's how it looks in the Document Outline pane:

Sample Image

and here's what we get for iPad 9.7":

Sample Image

Sample Image

and iPhone 11:

Sample Image

Sample Image

Preserve HTML font-size when iPhone orientation changes from portrait to landscape

You can disable this behavior through the -webkit-text-size-adjust CSS property:

html {
-webkit-text-size-adjust: 100%; /* Prevent font scaling in landscape while allowing user zoom */
}

The use of this property is described further in the Safari Web Content Guide.

IOS 6 view controller incorrect width / bounds - landscape mode

So this was a tough one. I load all my views programmatically. They basically are UIView subclasses that correspond to each view controller. For some reason, when an IOS6 view controller is opened from a parent view controller in landscape mode, the child view controller's bounds are not immediately passed on the child vc's UIView subclasses (if you just use addSubview in the viewDidLoad method of the controller--it is not enough). IOS7 does not have this problem.

The fix for IOS6 for me was doing the following in the viewDidLoad method of the child view controller:

//add view subclass to view controller
[self.view addSubview:views];

//reset bounds & refresh layout for IOS6
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
views.frame = self.view.bounds;
[views layoutIfNeeded];
}


Related Topics



Leave a reply



Submit