0000_0000_0000_0011 Frame and bounce

Source: Internet
Author: User

0000 0000 0000 0011

Written in2015.04.05 19:23

1.frame Bounce

These two days by UIScroll View engage in the dizzy, mainly still a few questions not fully understand, always think to fix them, and was a demo negative. Now it's possible to understand frame and bounce. So write it down and record it.

First of all, their storage is (x,y,width,height), to be divided into two parts (x, y) and (width,height). The former is Origin, and the latter is a size that represents points and dimensions, respectively.

1-1.frame

frame, from a hierarchical relationship, the position of the view on the View parent view SuperView .

Determines the position of the Child View ( subView ) on the parent view ( superView ) with two conditions, namely origin (one point) and size (the dimensions of the view). I think so, there is a canvas in front, draw a rectangle, there must be a pen place, that is origin, painting how much, that is, how much wider, how much higher, absolutely the last in the drawing how to present the rectangle.

The gray view bounce is (0,0,400,600) . Note that it's not a frame, and it's going to explain why it's bounce and what's different about picking (0,0) and taking other points.

Now I'm going to draw my green view on the gray views, as I said before, I'm going to set a starting point and size. Here is the point (100,60) , the size is 100 * 100, with a point ( point ) not yet, in the gray view I have to have a reference coordinate system, otherwise I know which point is (100,60) . This bounce (0,0) time plays a key role, it means that the top left corner of the view is represented (it is (0,0) important to have it in the figure , I'm talking about the dot in the upper left corner of the gray View (0,0)). The transverse right is the x-axis positive direction, and the vertical downward is the y-axis positive direction.

So I know the point (100,60) in which position, how much height to draw after the point is a simple question.

Write to this, basic and Baidu Google search for the same thing.

If I change the frame of the Green View (200,200,50,50), the position of the corresponding pen is different as the position of the point () is changed point , and the green view is finally moved to the lower right corner.

So far, these are all known to beginners. Finish talking about the frame and bounce.

1-2.bounce

Or next to the picture above, why should I emphasize the gray view just now bounce orgin (0,0) . Because in ScrollView this bounce will change (of course I don't want to involve too much here).

To know that we usually use the view when the bounce will print the next, usually origin (0,0),

Have you ever wondered what this point represents? What happens when you change the value of it?

Now give another picture:

The painting is rough, and later on he can read Orz. First the white view ( view1 ) is the parent view, then the gray View ( view2 ) add to the top, and the last Green View ( view3 ) Add to the gray view. As for the blue box, please ignore it temporarily.
The main or gray view, first gray view in the white view position is fixed, and then modify the gray view bounce in the middle of the origin see, set to (10,20).

As you can see, the origin of bounce is the coordinates of the point in the upper left corner of the view, in exchange for a popular violent speech, I specify the upper left corner of the point is (10,20), perhaps the next moment I will designate it as (100,200), who knows?


Back to the topic, now that the upper left corner of the point is (10,20), then the original point coordinates (0,0) where? That's why I marked it with a blue frame, as you can see on the graph (0,0). But what we see on the screen is still the gray area!

Question what does this affect?

I see other friends ' blogs in the learning process, which can be summed up in two sentences: There is a view ViewA , which is the location of the frame parent view, and viewA it bounce determines the layout position of the ViewA child view in.

I now understand that in the gray view to draw my green view, it is necessary to set the starting point of the green view (that is, the frame upper left corner of the Green View Arrow callout position). If I say now that I am set to (200,200), then this point is relative to the origin (0,0), just as the blue box points out the origin. Of course you can also say that according to the point in the upper left corner (10,20), I can also know (200,200) where the point. This is OK, too.


The key is to understand that we have modified the gray view in the top bounce origin left corner of the specified gray view of the point represented by how much!

2. When the child view is determined in the parent view, change the parent view's bounce

Next, but it may take a little imagination here. First, the gray view bounce is (0,0,320,568) , add a green sub-view above frame=(200,50,50,50) .

Now reset bounce to (40,40,320,568) . As mentioned above, in the upper left corner of the gray view, the coordinate point is (40,40). So the origin (0,0) should be in the upper left-hand corner that we can't see (imagine)? Then the Green View's (200,50) position should also be changed, and the upper-left corner should be moved.

If it's not clear, then do this:
First, the upper left corner of the gray view is changed from (0,0) to (40,40), do you Know (200,50) The position of this point in the gray view?

I don't know? So do it.

Since the point coordinate of the upper left corner of the gray View is (40,40), where is the origin (0,0)? When you mark out the origin, mark the point (200,50). You will find that it has moved to the upper-left corner than the original!

And then the whole contentinset and contentoffset ...

0000_0000_0000_0011 Frame and bounce

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.