IOS screen adaptation and ios screen adaptation

Source: Internet
Author: User

[Switch] iOS screen adaptation, ios screen adaptation
I. iOS Screen Adaptation Development History

Device Adaptation Technology
4 (IPad not available) Directly use code computing
With iPad AutoResizing
IPhone rear with different screens AutoLayout
IPhone rear with more different screens SizeClass
Ii. Features of various technologies 1. directly use code computing

Because the screen sizes are the same, only horizontal and vertical screens can be calculated directly.

2. autoResizing

Suitable for the relationship between the control and its parent Control

Description of each attribute

Attribute Explanation
UIViewAutoresizingNone Will not change with the change of the parent View
UIViewAutoresizingFlexibleLeftMargin Automatically adjust the left margin of the view and parent view to ensure that the right margin remains unchanged
UIViewAutoresizingFlexibleWidth Automatically adjust the width of the view to ensure that the Left and Right distances remain unchanged.
UIViewAutoresizingFlexibleRightMargin Automatically adjust the right margin of the view and parent view to ensure that the left margin remains unchanged.
UIViewAutoresizingFlexibleTopMargin Automatically adjust the top margin of the view and parent view to keep the bottom margin unchanged.
UIViewAutoresizingFlexibleHeight The height of the view is automatically adjusted to ensure that the top and bottom margins remain unchanged.
UIViewAutoresizingFlexibleBottomMargin Automatically adjust the bottom margin of the view and parent view to ensure that the top margin remains unchanged.
  • If the autoresizesSubviews attribute of view is yes (yes by default), autoresizing takes effect.
  • From XCODE6, Storyboard & Xib is automatically deployed by default. Therefore, you need to manually adjust the layout to use autoresizing.
  • Autoresizing can be used in combination, for example:
    UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin
3. autoLayout

It helps us determine that the same Visual Unit should have the proper position and size (The relationship between any two views can be determined.)

1. autoLayout usage:

  • Directly create constraints
         [self.view addConstraint: [NSLayoutConstraint constraintWithItem:blueView         attribute:NSLayoutAttributeLeft         relatedBy:NSLayoutRelationEqual            toItem:redView         attribute:NSLayoutAttributeLeft        multiplier:1          constant:0]];
    In this way, although the amount of code is large, it is absolutely feasible and one of the most fundamental ways to use autoLayout.
  • VFL Language
    -(Void) viewDidLoad {[super viewDidLoad]; UIButton * button = [[UIButton alloc] init]; [button setTitle: @ "click" forState: UIControlStateNormal]; button. translatesAutoresizingMaskIntoConstraints = NO; [button setBackgroundColor: [UIColor blackColor]; [self. view addSubview: button]; NSArray * constraints1 = [NSLayoutConstraint constraintsWithVisualFormat: @ "H: |-[button]-|" options: 0 metrics: nil views: button]; NSArray * constraints2 = [NSLayoutConstraint constraintsWithVisualFormat: @ "V: |-20-[button (= 30)]" options: 0 metrics: nil views: NSDictionaryOfVariableBindings (button)]; [self. view addConstraints: constraints1]; [self. view addConstraints: constraints2];}

     

     
  • Use a third-party library, such:Masonry,UIView + AutoLayout......
2. Advantages of autoLayout:
  • Basically, you don't need to consider 3.5-inch, 4-inch, or the upcoming x. for different resolutions of an x-inch screen, you don't have to use the viewDidLoad method to determine where different controls should be placed under different resolutions, or write different storyboard and xib for different resolutions;
  • You can discard the code that calculates the height of tableViewCell and UILabel based on different texts, because autolayout will help you automatically calculate the height;
  • If your layout does not change significantly in the landscape or landscape, you do not need to write two sets of code or two storyboard/xib;
4. sizeClass

In iOS8, the Size Classes feature is added, which is an abstraction of the current Size of all iOS devices. Then we only divide the screen width and height into three situations: Compact, Regular: loose, Any: arbitrary.

In this way, it is integrated with the high school and the third school, in a total of 9 cases. As shown in. We can set different la S (including control constraints, or even display controls) in each case)


SizeClass.png

Understanding of sizeClass:
SizeClass divides iOS screens into different abstract concepts. These different abstract combinations correspond to different device screens. Therefore, sizeClass can be used for the same UI to adapt to all screens. Note: all of these adaptations are implemented using autoLayout. sizeClass is only responsible for providing different screen sizes.

Address: http://www.jianshu.com/p/10d7038c78ae

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.