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:
and here's what we get for iPad 9.7":
and iPhone 11:
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
How to Draw Lines Through Bootstrap Vertical Dividers
CSS Zebra Stripe Background Without Image
Chrome Does Not Support The CSS @Page
Object Oriented CSS: Catchy Buzz-Phrase or Legitimate Design Approach
How to Change The Scrollbar to Custom Design? (Avoid Using The Default Browser Look)
Using CSS Modules How to Define a Global Class
Twitter Bootstrap - Vertically Align Input with Label Inside Control-Group
Apply Different Styles to Input Text Field When Empty (Using CSS)
Fixed Position Background Image in Firefox Doesn't Work with Transformed Element. Is This a Ff Bug
How to Make CSS3 Columns on a Horizontal Plane
Vertically Align Text to The Bottom of The Box
Use Multiple Ids for Divs in CSS
How to @Import .CSS File as a .Scss File in Sass
How Can The Pseudo Element Detect The Height of The Non-Pseudo Element