The calculation idea of nine Gongge

Source: Internet
Author: User

(tablets may not be displayed in IE browser)

Before you start your notes, add a little bit of knowledge that you noted earlier:

Common properties and methods of UIView:

[Email protected] (nonatomic,radonly) UIView *superview;

Get your own parent control object

[Email protected] (nonatomic,radonly,copy) Nsarray *subviews;

Object that obtains all of its child controls (the order of the array elements determines the display hierarchy order of the child controls-the larger the subscript, the more it appears above)

3.-(void) Addsubview: (UIView *) view;

Add a child control view

4.-(void) Removefromsuperview;

Remove from parent control

5.-(UIView *) Viewwithtag: (nsinteger) tag;

Find the corresponding control based on a tag ID (usually a child control)

[Email protected] (nonatomic) cgrect frame;

The position and dimensions of the control holding the box in the parent control (the origin of the coordinates in the upper-left corner of the parent control)

[Email protected] (nonatomic) cgrect bounds;

The position and dimensions of the control rectangle (with its own upper-left corner as the origin of the coordinates, so bounds x, Y is typically 0)

[Email protected] (nonatomic) CGRect Center;

The position of the midpoint of the control, in the upper-left corner of the parent control, as the coordinate origin.

The following is the beginning of today's note-Nine Gongge calculation ideas:

    • Use the index of the control to calculate the row and column number of the control
    • Calculating the X-value of a control using a column number
    • Calculating the Y-value of a control using line numbers

Small details, broken knowledge:

    • When multiple controls are added, the control's index is the length of the array in which the control resides
    • The number of columns for a control is the remainder of the total number of columns for the control's index number, and the number of rows for which the index number of the control is modulo

code example (this code is intercepted from a whole piece of code, the entire code implementation of the function is: Click the Add button, to add products to the Panel, the total number of products in two lines three columns):

    1. Create a panel called Shopview (that is, a block in) to hold pictures and text

  

Note: SHOPVIEWW,SHOPVIEWH for the previously defined number, Shopx,shopy is calculated later.

2. Every click of a button, a product is added to the next position, the width of each product x2 is fixed, so in order to calculate the next product X value, you should first calculate the value of X3,

In this way, the x value of a block is several times the value of (X2+X3).

Note: Shopsview is the parent control that defines Shopview, which is the white background panel behind the Chinese block.

To this, nine Gongge's calculation idea and method all end.

Supplemental Knowledge (Shopsview is the parent control):

1. Subtract controls that exceed the bounds of the parent control: Self.shopsView.clipsToBounds = YES;

2. Take the last data in the array: [Shopsview.subviews Lastobject]

3. Delete the last view:[[shopsview.subviews in the parent control Lastobject] Removefromsuperview];

4.HUD:

AKA: Indicator/Mask/cover

Used to indicate what happened to the user. For example, the "network instability" prompt will appear on your phone.

Small summary OF Scheduled tasks:

1.performSelector

[Self performselector: (nonnull SEL) Withobject: (Nullable ID) Afterdelay: (Nstimeinterval)];

The first parameter refers to wrapping the method, using simultaneous @selector (method name)

The second parameter is passed to the parameter in the called method, or nil if there is no argument in the method

The third parameter fills in time-seconds, which is actually a double value.

2.GUD

Dispatch_after (Dispatch_time (dispatch_time_now, (int64_t) (Delayinseconds * nsec_per_sec)), Dispatch_get_main_queue (), ^{

Code to being executed after a specified delay

});

There are only two places to fill in, that is, ' delayinseconds ' the number of seconds, {} Fill in the code, referring to ' delayinseconds ' seconds after the code executed {}.

3.NSTimer

[Nstimer scheduledtimerwithtimeinterval: (nstimeinterval) Target: (nonnull ID) selector: (nonnull SEL) UserInfo: ( Nullable ID) repeats: (BOOL)];

The calculation idea of nine Gongge

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.