iOS development skills - Size Class and iOS 8 multi-screen adaptation (1)

0. Background:

In iOS development, Auto Layout can solve most screen adaptation problems. But when the iPhone 6 and iPhone 6 Plus were released, Auto Layout could no longer solve the complex screen adaptation problem.

Therefore, after iOS 8, Apple introduced Size Class, which is based on Auto Layout technology.

 

1. Enabling and using Size Class

Different from Auto Layout, Size Class cannot be managed through code programming and can only be used through IB (Interface Builder).

By default, the layout files such as Story Board have enabled Size Class. If it is not enabled, you can select Story Board->File Inspector->Select Use Size Classes

-> Click the Size Class button (wAny|hAny) on the layout toolbar, and the Size Class menu will pop up.

 

2. The nine-square grid of Size Class

The Size Class menu is a nine-square grid, which can be combined into 9 situations, each of which corresponds to a different layout.

 

wCompact | hCompact

 

 

baths | hCompact

 

 

wRegular | hCompact

 

 

wCompact | hAny

  

 

baths | HAny

 

 

wRegular | hAny

 

 

wCompact | hRegular

 

 

baths | hRegular

 

 

wRegular | hRegular

 

Compact - compact

That is, the screen space is relatively small. For example, when the iPhone is in vertical screen, the horizontal direction is Compact, and the vertical direction is Regular. At this time, the value is wCompact | hRegular.

 

Any - any

The value between Compact and Regular is Any, Any is generally used for iPad layout, and the value at this time is wAny | hAny.

 

Regular - normal

Normally, when the iPhone is in landscape orientation, the horizontal direction is Regular, and the vertical direction is Compact. At this time, the value is wRegular | hCompact. 

 

* wCompact | hCompact: For 3.5-inch, 4-inch, 4.7-inch iPhone in landscape orientation.

* wAny | hCompact: Applicable when the vertical orientation is Compact, such as iPhone landscape.

* wRegular | hCompact: for 5.5-inch iPhone in landscape orientation.

* wCompact | hAny: Applicable to all cases where the horizontal orientation is Compact, such as 3.5-inch, 4-inch, 4.7-inch iPhone's vertical screen.

* wAny | hAny: For all layout situations, this is the last option.

* wRegular | hAny: Applicable to all cases where the horizontal orientation is Regular, such as iPad landscape and portrait.

* wCompact | hRegular: Applicable to all iPhone portrait situations.

* wAny | hRegular: Applicable to all cases where the vertical orientation is Regular, such as iPhone portrait, iPad landscape and portrait.

wRegular | hRegular: Applies to all iPad landscape and portrait situations.

 

 

 

 

 

Reprinted in: https://www.cnblogs.com/davidgu/p/6357357.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324131897&siteId=291194637