For how to adapt iPhone devices to different Display sizes

Source: Internet
Author: User

For how to adapt iPhone devices to different Display sizes

 

------ About adaptation ------

1. What is adaptation?

Adaptation is applicable to different hardware and system software, including screen display, processor, memory, etc (currently mainly screen adaptation, iPhone 6 s has added the 3D Touch function, other hardware functions have not changed substantially). Software is mainly used in different iOS systems (some methods that are not supported in the latest systems (usually as backward compatible as possible) need to be judged ).

2. Why is adaptation required?

Adaptation is to be compatible with different devices.

3. What are the main methods for screen adaptation?

(1) Proportional adaptation (all views are scaled by screen size and their relative positions remain unchanged): a, pure code; B, code + storyboard (no automatic layout is used ); c. Code + storyboard (use automatic layout ).

(2) free adaptation (mainly using automatic layout): Because the same layout shows different effects on screens of different sizes, if only proportional scaling is used, sometimes the display effect is unsatisfactory; when the size of the displayed content conforms to the operation habits (depending on what you want), the biggest difference between the screen size and the large display content (such as browsing news, etc, in addition to some concise interfaces such as fixed images and controls, a. Restrict the spacing and relative size of the content; B. Restrict the width and height of the content and the relative position; c. Restrict the content spacing and width and height.

 

------ Adaptation methods ------

Scenario 1

(Proportional adaptation, code + storyboard, do not use automatic layout, we recommend that you use the iPhone 6 size layout), by getting the screen size, redefinition of CGRectMake, update the frame of all views and their subviews, completes proportional adaptation. Pay attention to fonts, images, and tableView and collectionView.

1. ------ add AppDelegate. h:

+ (Void) ergodicView :( UIView *) view;

 

2. ------ add AppDelegate. m:

# Define ScreenHeight [UIScreen mainScreen]. bounds. size. height

# Define ScreenWidth [UIScreen mainScreen]. bounds. size. width

# Define ScreenScaleX (ScreenWidth/375) // relative to the apple 6 screen

# Define ScreenScaleY (ScreenHeight/667)

 

// Automatically adapt to all views of the storyBoard by Screen

+ (Void) ergodicView :( UIView *) view {

If (view. subviews. count! = 0 ){

For (UIView * temp in view. subviews ){

Temp. frame = CGRectMake1 (temp. frame. origin. x, temp. frame. origin. y, temp. frame. size. width, temp. frame. size. height );

[Self ergodicView: temp];

}

}

}

 

// Modify CGRectMake

CG_INLINE CGRect

CGRectMake1 (CGFloat x, CGFloat y, CGFloat width, CGFloat height)

{

CGRect rect;

Rect. origin. x = x * ScreenScaleX;

Rect. origin. y = y * ScreenScaleY;

Rect. size. width = width * ScreenScaleX;

Rect. size. height = height * ScreenScaleY;

Return rect;

}

 

--------------------

Case 2

After autolayout is used, You can reset the frame of the view. After viewDidLoad is loaded, the frame of the view is delayed. The frame is reset by the storyboard without delay. You can also reset the frame in viewDidLayoutSubviews or viewDidAppear.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.