View of the Ui-Foundation

Source: Internet
Author: User

------------------------------UIWindow--------------------------//

1. UIWindow: is a subclass of UIView for managing and coordinating the windows displayed in the application it is the root view in the view

IOS applications typically have only one UIWindow, the application creates this UIWindow at startup, joins one or more views into the window, and then displays it, UIWindow is created based on the size of the device, and if it exceeds the device size, the excess is not displayed. Nor can I manipulate the events of the Super View (rotate, click, etc.)

(UIWindow is like a wall, the size of the wall is based on the size of this room, if you uiwindow this wall more than the room size, you in the room outside the walls of the wall affixed with your photos, you are in the house you can not see the photos you posted in the house to the outside of the wall to take off photos)

UIWindow main functions:

1, he is a container for the view to provide a display area;

2, the event (such as: rotation, click, etc.) distributed to the view

Main properties of UIWindow:

1, Keywindow: (@property (Nonatomic,readonly,getter=iskeywindow) bool Keywindow;) bool type, read-only, determines whether the current application is Keywindow ( Keywindow refers to the UIWindow that can receive keyboard input and other non-touch events, only one Keywindow)2, Rootviewcontroller:uiviewcontroller (View Controller) type, Add a root view controller to a UIWindow

----------------------------UIView------------------------------//

1. Uiview:uiview is a view that represents a rectangular area on the screen. Various UI controls belong to view, and different controls belong to different kinds of views, and all you can see in iOS is UIView or its subclasses.

2. Create a view: Initialize the view and give him a coordinate to add the view to the layer you want to display

The Frame:cgrect type is the coordinate that is the position and size of the view you want to add. He is a struct, the structure of which has Origin starting position (in 2D to determine a position, can be determined with two points (such as the x-axis y-axis (10,20))), as well as size itself, has a starting position, and then set his focus position, you can get his size

struct CGRect {//defines a struct called CGRect that contains origin (the distance from the X, Y origin to Origin) and a size called the Cgsize type (the size of the view) that is called the Cgpoint type

Cgpoint origin;

Cgsize size;

};

typedef struct CGRECT cgrect;//represents a struct CGRect and cgrect is the same thing

View hierarchy: 1, if two view coordinates are added first, the view will be overwritten

The Center:cgpoint type is the center point of the view in the parent view's coordinate system, relative to the parent viewport.

Bounds: Refers to the size of the view in the coordinate system of the view itself (the starting point of the position is the origin (0,0, the width of the view, the height of the view)).

how to calculate center :

 //  center.x = FRAME.ORIGIN.X-FRAME.SIZE.WIDTH/2;

Center.y = FRAME.ORIGIN.X-FRAME.SIZE.WIDTH/2;

------------------------- Adjustment of the View hierarchy ------------------------//

In the actual development of the project, you may encounter the need to move a view to the lowest level, or to move to the top of the operation, we use the lesson of the hierarchy of the adjustment

The main method to use:

addsubview: Add a sub-view to the receiver and let it show up on top of it

Bringsubviewtofront: Move the specified sub-view to the top level

sendsubviewtoback: Moves the specified child view to the back of its adjacent view

removefromsuperview: Removing views

Code implementation:

When we add a child view above the same parent view, the system automatically helps us to record an index as soon as we add a sub-view it will increase by 1. Starting from 0.

Removefromsuperview Removing views from parent View

[Gview Removefromsuperview];

Summary: A child view is dependent on the parent view, and the child view position changes if the parent view position changes

Because frame defines location information based on its parent view.

If you remove the parent view, the child view above will be removed

---------------View Center Point-------------------

Center Point

Change the center point of the parent view relative to its parent

X = width/2; Y = high/2;

------------- three ways to get the center point ------------------

The first type:

View.center = Cgpointmake ([UIScreen mainscreen].bounds.size.width/2, [UIScreen MAINSCREEN].BOUNDS.SIZE.HEIGHT/2];

The second type:

//View.center =cgpointmake (Cgrectgetwidth ([UIScreen mainscreen].bounds)/2, cgrectgetheight ([UIScreen Mainscreen].bounds)/2);

The third type:

The true center point of the parent view

View.center = Self.window.center;

View of the Ui-Foundation

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.