-
Notifications
You must be signed in to change notification settings - Fork 421
CAView
View class CAView is the most basic class of the whole CrossApp and is in charge of displaying all kinds of interfaces, actually all interfaces we can see in App is single CAView combination. CAView, who is responsible of defining rectangle region on screen, plays a pivot role on displaying user interface and responding its interaction. As an essential mechanism of application’s user interaction, each view object has responsibility on rendering content of view rectangle region, and responding operation event that happened within this region.
View is also a controller of one or multi child views except for displaying content and dealing with event. We can add multi child views on a view which as a parent view, namely parent node, is in charge of managing its child view and modifying their position and size by requirements, and responding the unsettled events of these child views.
CAResponder
Access modifier |
Attribute name |
Description |
public |
Frame |
Position size relative to parent view |
public |
Bounds |
Position size relative to its own |
public |
Center |
frame of view center point |
public |
Color |
View color |
public |
Alpha |
View transparency |
public |
ZOrder |
Z axis value |
public |
Scale |
View’s scale ratio |
public |
Visible |
Visible or not |
public |
Rotation |
Rotation |
public |
Tag |
tag |
Access modifier |
Method name |
Description |
public |
create |
Build a blank view, Frame is (0,0,0,0) by default |
public |
createWithFrame |
Build a view and appoint its Frame |
public |
createWithFrame |
Build a view and appoint its Frame and Color |
public |
createWithCenter |
Build a view and appoint its Center |
public |
createWithCenter |
Build a view and set its Center and color |
public |
createWithColor |
Build a view and appoint Color, Frame is (0,0,0,0) by default |
public |
addSubview |
Add child view into current view |
public |
insertSubView |
Add child view into current view and appoint a Z axis value |
public |
getSubviewByTag |
Obtain child view by tag value |
public |
getSubviews |
Obtain child view’s collection |
public |
getSubviewsCount |
Obtain child view’s count |
public |
removeFromSuperview |
Remove from parent view |
public |
removeSubview |
Remove child view |
public |
removeSubviewByTag |
Remove child view by tag value |
public |
removeAllSubviews |
Remove all child views of current view |
public |
reorderSubview |
Record child view and its corresponding tag value |
public |
sortAllSubviews |
Sort all child views of current view |
Frame
Type: CCRect
Description: it determines view’s position and size on screen, and takes parent view’s coordinate system as reference, and here the frame’s attribute is shared attribute of view and its child class. CCRect contains two members: one is starting coordinate ‘origin’, and the other is width and height ‘size’, we must appoint a Frame when building a view otherwise there will be no visible effect. For CAView and its child class’s frame operation, when we deal with createWithFrame, setFrame and etc. operations, if size member of CCRect is set as (0,0), then view size is unchanged; if you only want to change view’s coordinates and stay view’s size the same, then you can set with setFrameOrigin method, get/set{}.
Bounds
Types: CCRect
Description: view’s position and size in its own coordinate system which is also the reference, CCRect’s origin value always is (0,0), and bounds’ attribute is shared by view and its child class. When we set frame, bounds is determinate and its value is same with frame, and they do have difference: frame value will change with view’s scale operation, and bounds value will not change, get/set{}.
Center
Type: CCrect
Description: view center point’s position on screen, CrossApp employs screen coordinate system: left upper corner is original point, and rightward and downward directions correspond respectively X and Y axis. In CrossApp we determinate a view’s position through origin and size, for convenience we can directly use Center to set view’s center point on our desired position. If you only want to change view’s coordinates and stay view’s size the same, then you can set with setFrameOrigin method, get/set{}.
Color
Type: CAColor4B
Description: view color, white view by default, get/set{}.
1 2 3 4 5 6 7 8 9 10 |
CCRect winRect = this->getView()->getBounds();
CAView* view = CAView::createWithFrame(CCRect(300,300,200,200),ccc4(255,0,0,255)); view->setCenter(CCRect(winRect.size.width*0.5,winRect.size.height*0.5,0,0)); view->setColor(ccGREEN); CALabel* tf = CALabel::createWithFrame(CCRect(20,20,0,0)); tf->setText(“view”); tf->setFontSize(25); view->addSubview(tf); this->getView()->addSubview(view); |
Build a view and appoint view’s frame and set color as green.
Alpha
Type: float
Description: view’s transparency, its value within 0 - 1, when we set alpha, view and all its child class’s transparency value will change. If we only need to set current view’s transparency, then use createWithColor method to appoint at the fourth parameter. Opacity by default, get/set{}.
ZOrder
Type: int
Description: view’s Z axis attribute, it supports overlaying among multi views, overlays views in order by setting Zorder and determinate view’s covering relationship, get/set{}.
Scale
Type: float
Description: view supports scale operations, which includes X and Y axis scale at the same time ‘Scale’, X axis scale ‘ScaleX’ and Y axis scale ‘ScaleY’, get/set{}.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
CAView* view1 = CAView::createWithColor(ccc4(255,0,0,255)); view1->setCenter(CCRect(600, 400,200, 200)); CALabel* tf1 = CALabel::createWithFrame(CCRect(100,100,0,0)); tf1->setText(“view1”); tf1->setFontSize(25); view->addSubview(tf1); this->getView()->insertSubview(view,1);
CAView* view2 = CAView::createWithColor(ccc4(0, 0, 255, 255)); view2->setCenter(CCRect(500, 300, 200, 200)); view2->setScale(0.5); view2->setZOrder(2); CALabel * tf2 = CALabel::createWithFrame(CCRect(50, 50, 0, 0)); tf2->setText(“view1”); tf2->setFontSize(25); view2->addSubview(tf2); this->getView()->addSubview(view2); |
Set view’s hierarchical relationship by changing Z axis value and scale view at the same time.
Visible
Type: bool
Description: view is visible or not, is/set{}.
Rotation
Type: float
Description: view’s rotation which includes XY axis rotation, X axis rotation and Y axis rotation, get/set{}.
Example:
1 |
view1->setRotation(60); |
It rotates view1 60-degree.
Tag
Type: int
Description: view’s tag value, get/set{}.
static CAView * create(void)
Return value: CAView*
static CAView createWithFrame(const CCRect& rect)*
Return value: CAView*
Parameter:
Type |
Parameter name |
Description |
CCrect |
Rect |
View’s position and size |
static CAView createWithFrame(const CCRect& rect, const ccColor4B& color4B)*
Return value: CAView*
Parameter:
Type |
Parameter name |
Description |
CCRect |
rect |
View’s position and size |
CAColor4B |
Color4B |
View’s color |
static CAView createWithCenter(const CCRect& rect)*
Return value: CAView*
Parameter:
Type |
Parameter name |
Description |
CCRect |
Rect |
View center point’s position and view’s size |
static CAView createWithCenter(const CCRect& rect, const ccColor4B& color4B)*
Return value: CAView*
Parameter:
Type |
Parameter name |
Description |
CCRect |
Rect |
View center point’s position and view’s size |
CAColor4B |
color4B |
View’s color |
static CAView createWithColor(const ccColor4B& color4B)*
Return value: CAView*
Parameter:
Type |
Parameter name |
Description |
CAColor4B |
color4B |
View’s color |
virtual void addSubview(CAView * child)
Return value: void
Parameter:
Type |
Parameter |
Description |
CAView* |
Child |
Child view |
virtual void insertSubview(CAView subview, int z)*
Return value: void
Parameter:
Type |
Parameter name |
Description |
CAView* |
Child |
Child view |
CAView * getSubviewByTag(int tag)
Return value: CAView*
Parameter:
Type |
Parameter name |
Description |
Int |
Tag |
Tag value |
virtual CCArray getSubviews()*
Return value: CCArray*
Description: obtain all child views of current view and return child view array.
unsigned int getSubviewsCount(void) const
Return value: unsigned int
Description: return an unsigned int type value to identify current child view number.
virtual void removeFromSuperview()
Return value: void
Description: remove current view from parent view.
virtual void removeSubview(CAView subview)*
Return value: void
Type |
Parameter name |
Description |
CAView* |
Subview |
Child view |
virtual void removeSubviewByTag(int tag)
Return value: void
Parameter:
Type |
Parameter name |
Description |
Int |
Tag |
Tag value |
virtual void removeAllSubviews()
Return value: void
Description: remove all child views of current view.
virtual void reorderSubview(CAView * child, int zOrder)
Return value: void
Parameter:
Type |
Parameter |
Description |
CAView* |
Child |
Child view object |
Int |
zOrder |
Z axis value |
virtual void sortAllSubviews()
Return value: void