May 21, 2021 CrossApp
1. The underlying coordinate system
3. Up and down left and right margins, center points, wide height
When we learn CrossApp, we can make sure that the basic conceptual things can greatly improve the efficiency of our study of CrossApp.
Let's talk briefly about CrossApp's coordinate system today.
CrossApp uses a coordinate system that is the screen coordinate system, i.e. the upper left corner is the origin, the right is the X-axis growth direction, the downward corresponding Y-axis growth direction.
Pictured:
In addition to displaying content and handling events, you can try to manage one or more sub-views.
We can add multiple childviews to a view, and as parentviews, the parent nodes, are responsible for managing their direct child views and adjusting their position and size as needed, as well as responding to events that they have not handled.
Based on the class description, we can draw the following conclusions:
Newbies may not understand the concept of parent nodes and child views and B is added to A, and if at this point we adjust the coordinate position of A, then B will change with the coordinates of A. S
o we say: B is the child node of A (also known as the child view), and A is the parent node of B. S
ince B is a child of A (sub-view), B can use A's node coordinate system
I draw a picture to illustrate:
As shown in the figure, the two CAViews shown on the screen are A and B, respectively.
CAView defines a property
in the coordinate system: DLayout.
The API is defined as follows:
Layout
Type:
DLayout
Explanation:
Determines how view appears on the screen.
//Frame
CAView * frameView = CAView::createWithColor(CAColor_blue);
frameView->setFrame(DRect(100, 100, 100, 100));
//this->getView()->addSubview(frameView);
//添加并设置z为2
this->getView()->insertSubview(frameView, 2);
//Bounds
CAView* boundsView = CAView::createWithColor(CAColor_red);
boundsView->setBounds(DRect(300, 300, 100, 100));
this->getView()->addSubview(boundsView);
//Center
CAView* centerView = CAView::createWithColor(CAColor_orange);
centerView->setCenter(DRect(100, 100, 100, 100));
//this->getView()->addSubview(centerView);
//添加并设置z为1
this->getView()->insertSubview(centerView, 1);
Changes in frame andbounds after testing View zoom:
//缩放后的Frame和Bounds
frameView->setScale(2);
DRect frameRect = frameView->getFrame();
DRect boundsRect = frameView-> getBounds();
CCLog( "frameView->getFrame():x:%f,y:%f,width:%f,height:%f", frameRect.getMinX(), frameRect.getMinY(), frameRect.getMaxX() - frameRect.getMinX(), frameRect.getMaxY() - frameRect.getMinY() );
CCLog( "frameView->getBounds():x:%f,y:%f,width:%f,height:%f", boundsRect.getMinX(), boundsRect.getMinY(), boundsRect.getMaxX() - boundsRect.getMinX(), boundsRect.getMaxY() - boundsRect.getMinY() );