IOS_BOOK03-Auto-rotate, auto-resize, size classifier

Source: Internet
Author: User
Tags compact uikit

Auto-Rotate (autorotation): Enables applications to be used in portrait mode (long and narrow) or landscape mode (short and wide), enabling you to change the orientation of the application while rotating the device.   Apple recommends that most applications on the ipad should support all directions. For iphone apps, the basic principle is that if auto-rotation enhances the user experience, they should be added to the app. For ipad apps, adding auto-rotation is an iron.   NOTE: If the application displays the status bar, the actual space available for the program on the vertical screen will be reduced by 20 points in the vertical direction. The status bar is located at the top of the screen with a height of 20 points for information such as signal strength, time, and battery power. The dot, pixel, and retina display Retina display is Apple's sales term for all subsequent iphone models, IPhone4 ipod Touch, and the latest ipad high-resolution screens used. When you manipulate an interface element on the screen, you specify its size and distance by using dots rather than pixels. For the early iphone (and the ipad, iPad2, and ipad mini1), dots and pixels are equivalent, and a point is a pixel. However, on newer iphones, ipads, and ipod Touch, 1 points are equivalent to 4 pixels of area (width and height are 2 pixels). For example, the iphone5s screen width is actually 640 pixels, but it still behaves as 320 points. In Iphone6plus, the scale is 3. So each point corresponds to a 9-pixel square. Since iOS automatically maps points to the physical pixels of the screen, you can think of points as virtual resolution (resolution).   to cope with device rotation, you need to specify the appropriate constraints for all objects in the interface. When you adjust the view, the constraint tells the iOS device how to adjust the controls.   The constraint can be understood as an equation that describes the geometry of the view, and the iOS view system is the solver that adjusts the views as necessary to satisfy the geometry properties described by the equation.    There are two ways to set iOS view to support interface rotation: One is to create an application-level setting (which will be the default support direction for all view controllers), or to make further adjustments for each independent attempt controller.   Application-level support direction: in the general interface of the project setup, you can see a section titled Deployment Info, which contains a set of check boxes called device orientation, which is the way to specify the direction the application supports. This does not mean that each view in the app supports the selected orientation, but if you want all the application views to support a certain direction, you mustThis direction is selected here. By default, the upside down direction (where the home key is located) is not selected, because if you call when the iphone is upside down, the phone may not still be inverted when you answer the phone. The Device orientation check box is really just a convenient way to add and delete related items in your app's Info.plist file.   Independent controller for optional turn support. The view controller is configured so that it supports different orientations (a subset of the application-level payment direction), note: We specify the absolute upper limit of the direction that the app supports in the global configuration of the app. If the global configuration does not support the upside down direction, then no one view controller can force the system to go to the upside down direction. What can be done in a view controller is to make further restrictions within an acceptable range.   Defines the method in the parent class Uiviewcontroller, which can specify the direction supported by the current View controller: Swift:override Fun supportedinterfaceorientations-Int {      return Int (UIInterfaceOrientationMsk.Portrait.rawValue) | Int (UIInterfaceOrientationMask.LandscapeLeft.rawValue)} objective-c-(Nsuinteger) supportedinterfaceorientations {
    Return (uiinterfaceorientationmaskportrait             | Uiinterfaceorientationmasklandscapeleft);}   This method uses a C-style mask to return all supported orientations. This is how iOS asks if a view controller supports rotating to a specified direction. In this method, the return value means that you can accept two directions: The default portrait orientation and the landscape after 90 degrees clockwise (that is, the direction of the left edge of the phone when it is over). Use the OR operator to combine two directional masks together as a return value.  uikit defines the following directional masks (in swift, for example), which can be combined with any combination of the OR operator. UIInterfaceOrientationMask.PortraitUIInterfaceOrientationMask.LandscapeLeftUIInterfaceOrientationMask.LandscapeRightUIInt Erfaceorientationmask.portraitupsidedown In addition, there are several predefined general combined values that are fully equivalent to using the OR operator directly with these combined values: Uiinterfaceorientationmask.landscapeuiin terfaceorientationmask.alluiinterfaceorientationmask.allbutupsidedown  when the iOS device is rotated to a new direction, The Supportedinterfaceorientations method is called on the currently active view controller. If the return value of this method contains a new direction, the application rotates the current view, otherwise it does not rotate. Because each view controller subclass can override this method, it is possible for an application to have some views support rotation, while another view is not supported, and for a single view controller, a specific orientation can be supported under certain conditions.   ios actually have two different types of orientations. The interface direction (interface orientation) is discussed here. Another independent, but related, concept is device orientation. The device orientation indicates the current holding mode of the device, while the interface direction isrefers to the direction of rotation of the view on the screen. If the iphone upside down, then the device method is inverted, but the interface direction is only one of the other three directions, because the iphone app does not support the upside down direction by default.    editor>resolve Auto Layout issues > Add Missing constraints option to add a constraint to the left and right corner labels. Then you can see that there are some blue solid lines next to the label. Each solid blue line represents a constraint. Press Option+command+5 to open the dimension inspector (Size Inspector) and you can see a list with constraints in it.   in the label, where two constraints are responsible for handling the relationship between the current label position and the parent view (that is, the container view): It specifies the front padding (leading space, which usually means the spacing to the left) and the bottom padding (bottom space, the spaces below the label). When the size of the parent view changes (such as device rotation), these constraints cause the labels to be spaced from the top and left of the parent view.  pin>horizontal spacing option, this constraint tells the layout system to keep the same horizontal spacing between these labels as they are currently.   Make sure that a label is selected, hold down the SHIFT key, and click another label. This allows both tags to be selected, and then you can create a constraint that works on both tags.   If you add an unwanted constraint incorrectly, you can either select the constraint and press the DELETE key to remove it, or configure it in the property inspector.   Create a relative distance between two spaces, you can move the mouse over a control, then hold down the right button, drag the mouse over another control, and then select the desired constraint in the popup panel.    before iOS8, you would need to implement the entire layout or multiple storyboard in your code, or both, to design multiple separate interfaces for different situations. However, after IOS8 and Xcode 6, only a single storyboard can be used to design adaptive applications that can run in all directions and on different devices.   can create different groups of constraints through the dimension classifier to correspond to different display situations.   In the toolbar, you can see a label called the dimension classification control that looks like a text Wany Hany. Clicking on this control will bring up a panel with a grid of 9 cells. The cells in the grid correspond to different horizontal (width) and vertical (height) dimension classification combinations. Dimensional classification is a general classification of the device's high width. There are two kinds of specificThe dimension classifications are used to represent the real machine: compact and Standard (Regular). There is also a third category that can be used in the design tool (and in the code) to represent both compact or standard: arbitrary (any).   Dimension classification with device and direction mapping: aspect are compact, mapped devices and directions are out of iPhone6 plus all horizontal screen iphone wide compact high standard, mapped is all vertical screen iphone wide standard high compact, mapped is the horizontal screen of the iphone 6 The plus aspect is standard, with all the ipad mapped to a horizontal and vertical screen.   Usually, compact means smaller than the standard, but there are two interesting places to note: 1.iPhone in portrait mode is compact width and standard height, this is not difficult to understand, because in this direction width is smaller than the height. However, after rotating to the horizontal screen mode, the width and height of the size classification are compact, not standard width and compact height. The only exception is the large size iphone 6 Plus, which is the standard width and compact height. This means that the two dimension classifications are considered when deciding on the layout. The 2.iPad is standard width and standard height both horizontally and vertically, which means that the orientation of the ipad cannot be determined using only dimension classifications. This is not a problem in many cases, because the ipad has a relatively large screen and is closer to the square than the iphone, which allows you to use the same layout in both portrait and landscape orientation.   Below is a graphical way to show the mapping of dimension classifications:  back in the project, you can see the dimension classification control in the storyboard editor, which is Wany hAny by default. This means that the design in the storyboard editor is valid for size classification of any width and height. I call it a universal design. You should always start with a generic design and then modify the general design as needed. By selecting a combination in the dimension classification control, you can modify the design that fits it and not affect the universal design.   for all iphones (other than iphone 6 Plus) should be a compact height and a compact width, so the size classification should be wcompact and hcompact, however we want to use the same design on the iphone 6 Plus Its parameters are wregular and hcompact. By summing them together, it is possible to achieve a design that can be displayed normally at any width and in a compact height. Select the following: The design can be modified in 3 ways for any combination of dimension classifications, and changes will only work on the device and direction represented by the current dimension grouping. 1. You can add, remove, or modify constraints. 2. You can add or remove views. 3. You can change some uikit controls (there are uilabel in iOS8, Uitextfield, Uitextview, and UIButton) fonts.   Now the design is different from the general design, because all the views change position, so you need to remove all existing constraints. Before making a change, select Storyboard, open the auxiliary editor, and select Preview in the secondary editor jump bar to open the storyboard preview screen, which shows the iphone's portrait appearance. We will use this preview interface to ensure that the changes we make are not affected by the universal design.   Should develop a secondary editor once each modification to ensure that the design of the vertical screen is unaffected. If there is a problem, do not resolve it by continuing to modify it, but instead use the Command+z shortcut to cancel the last few steps back and forth to the correct layout before continuing the attempt.   It is wrong to replace the control's original constraints, select them in the document outline, and delete them. Deleting a constraint removes it from all the dimension grouping combinations. The unload constraint should be in the design for the currently edited dimension classification combination.   Select a control in storyboard and open the Dimension inspector, you can find the previously added three constraints, double-click the top constraint, you can display detailed information, such as: you can see the bottom of the installed check box is currently checked. We need to unload this constraint from this design. By pressing the plus button on the left side of the check box and selecting any Width in the popup panel | Compact Height. This adds a new check box for Wany and hcompact layouts only. Uncheck it to unload this constraint from this size grouping, which is still valid in a common design. There is also a quick way to  IOS9 after the control is selected, click Resolve Auto Layout issues>clear constrains to unload the constraint. When you unload a constraint, you can see that the constraints in storyboard are not available and are dimmed in both the document outline and the Dimension checker. You can confirm that all constraints are emptied by selecting each control and checking that they are grayed out in the dimension inspector.   NEW constraint, click Pin, uncheck the constrains to margins checkbox in the pop-up box, then add the required constraint.   The new controls in the dimension class combination will only appear in the category size combination.   Change the size of the font in the new size category combination, and also add a new dimension class combination to the font, and then modify the font.                                                               

Ios_book03-Auto-rotate, auto-resize, size classifier

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.