×

一、简介与环境搭建

CrossApp简介CrossApp摘要CrossApp坐标系浅谈CrossApp屏幕适配方案CrossApp源码结构CrossApp的MVC模式CrossApp项目结构及入口CrossApp内存管理CrossApp类结构图创建CrossApp工程CAVector、CAList、CADeque、CAMap(数据容器)Windows 开发下VS2013环境搭建Windows 开发下Android环境配置Mac OS 开发下Xcode环境搭建Mac OS 下iOS移植android环境配置

二、CrossApp简单控件的使用

DLayout(自适应布局)CALabel(显示文本)CAImage、CAImageView(显示一张图片)CAScale9ImageView(九宫格图片拉伸)CAButton(按钮)CATextView(多行输入框)CATextViewDelegateCASwitch(开关控件)CAProgress(进度条)CAAlertView(提示框)CAScrollView(滚动视图)CAScrollViewDelegateCAListView(列表)CAListViewDataSourceCAListViewDelegateCATableView(表单视图)CATableViewDataSourceCATableViewDelegateCATableViewCellCACollectionView(容器)CACollectionViewDataSourceCASlider(滑动条)CAStepper(步进控件)CAPageView(页面切换)CAPageViewDelegateCAWaterfallView(瀑布流控件)CAWaterfallViewDataSourceCAWaterfallViewDelegateCAWaterfallViewCellCATextField(输入框)CATextFieldDelegateCAAutoCollectionView(自动化布局容器)CAAutoCollectionViewDataSourceCAAutoCollectionViewDelegateCAVideoPlayerControlView(视频播放器控制视图)CAVideoPlayerControlViewDelegateCAWebView(Web视图控件)CAWebViewDelegateCAGifView(显示Gif图片)CARenderImage(图像渲染)CASegmentedControl(分段控制)CAPickerView(视图选择器)CAPickerViewDataSourceCAPickerViewDelegateCAActivityIndicatorView(活动指示器)CrossApp UIEdit(UI编辑器)

三、视图控制

CAViewController(视图控制器)CADrawerController(抽屉控制器)CANavigationController(导航控制器)CANavigationBarDelegateCANavigationBarItemCANavigationBarCATabBarController(标签栏控制器)CATabBarDelegateCATabBarItem

四、调用系统支持

CADevice

五、数据的解析与存储

CAUserDefault简单存储SQlite的使用json解析xml解析

六、网络

网络通信之httphttp请求网络图

七,动画

CAViewAnimation(动画实现)

八、宏定义

宏定义

九、其他控件的使用

CAViewCAViewDelegateCATextField(输入框1.2以前版本)CAObjectCAResponderCAPullToRefreshViewCAControlCAWindowCABarItemCABarButtonItemCASchedulerCAMediaDelegateCAKeypadDelegate

CAListView(列表)


类说明

CAListView和CAScrollView非常相似,只是其内部成列表状,支持水平方案和竖直方向的滑动。常用于一些列表信息的展示,如:通讯录、新闻列表、目录索引等。


CAListView使用起来相对比较复杂,一般我们要同时使用CAListView、CAListViewCell、CAListViewDelegate、CAListViewDataSource来同时构建我们的列表界面,这么我们先分别了解一下它们的作用:

CAListView就是列表控件,是显示列表的载体,它是由多个CAListViewCell列组成的。

CAListViewCell是组成列表的每一个单元,下面我们都简称为cell

CAListViewDelegate是CAListView的交互代理,主要代理选择cell和取消选择cell的事件

CAListViewDataSource是CAListView的数据代理,主要代理cell的数量、cell的高度和将cell添加到CAListView显示。


CAListView 属性(点击查看方法介绍)

属性 说明
ListViewOrientation listView的滚动方向
ListViewDataSource 添加数据代理
ListViewDelegate 添加交互代理
ListHeaderView 添加头部视图
ListFooterView 添加尾部视图
SeparatorColor 设置cell分割线的颜色
ListHeaderHeight 设置头部视图的高度
ListFooterHeight 设置尾部视图的高度
SeparatorViewHeight 设置cell分割线的高度
AllowsHeadAndFootHover 允许头和尾的悬停
AllowsSelection 是否开启cell选择
AllowsMultipleSelection 是否可以多选cell


CAListView 方法(点击查看方法介绍)

方法 说明
setAllowsSelection 是否开启cell选择
setAllowsMultipleSelection 是否可以多选cell
setSelectAtIndex 根据索引设置cell为选中状态
setUnSelectAtIndex 根据索引设置cell为未选中状态
setShowsScrollIndicators 设置显示滚动条
dequeueReusableCellWithIdentifier 可以重用单元标示符
cellForRowAtIndex 通过cell索引获取Index
switchPCMode 开关PC模式
ccTouchBegan 触摸事件开始时的回调函数
ccTouchMoved 触摸事件中触点移动时的回调函数
ccTouchEnded 触摸事件结束时的回调函数
ccTouchCancelled 触摸非正常结束时的回调函数。(例如:电话或锁屏)
mouseMoved 鼠标移动
mouseMovedOutSide 鼠标移出


CAListViewDelegate 方法(点击查看方法介绍)

方法 说明
listViewDidSelectCellAtIndex 选中cell时调用
listViewDidDeselectCellAtIndex 取消选择cell时调用


CAListViewDataSource 方法(点击查看方法介绍)

方法 说明
numberOfIndex cell的总数量
listViewHeightForIndex cell的高度
listViewCellAtIndex 添加生成cell
listViewWillDisplayCellAtIndex 回调当前将要显示的CAListView


CAListViewCell 属性(点击查看方法介绍)

属性 说明
ContentView 获得内容视图
BackgroundView 设置背景视图
ReuseIdentifier 设置重用标识符
Index 获得重用标识符
ControlStateEffect 设置控制状态效应
AllowsSelected CAListViewCell是否可以选择


CAListViewCell 方法(点击查看方法介绍)

方法 说明
create 创建,默认Frame为(0,0,0,0)
initWithReuseIdentifier 重用标识符初始化


了解CAListView的主要函数,我们来实现一个CAListView的列表视图。

第一步:创建我们自己的cell

我们需要创建一个先的class,我这里创建一个MyCell,并继承CAListViewCell。用于每个列表单元的布局显示,下面看一下MyCell.h和MyCell.cpp的代码实现。

#pragma once
#include "CrossApp.h"
class MyCell : public CAListViewCell
{
public:
    MyCell();
    ~MyCell();
     
    //创建MyCell
    static MyCell* create(const std::string& identifier, const DRect& _rect = DRectZero);
     
public:
    //初始化Cell
    void initWithCell();
    
    //设置回调
    void cellBtnCallback(CAControl* btn, DPoint point);
     
protected:
    //正常状态
    virtual void normalListViewCell();
    
    //高亮状态
    virtual void highlightedListViewCell();
    
    //选中状态
    virtual void selectedListViewCell();
    
    //禁用状态
    virtual void disabledListViewCell();   
};

MyCell.cpp代码如下:

#include "MyCell.h"
 
MyCell::MyCell()
{
}
 
MyCell::~MyCell()
{
}
 
MyCell* MyCell::create(const std::string& identifier, const DRect& _rect)
{
    MyCell* listViewCell = new MyCell();
     
    //设置重用标示符
    if (listViewCell&&listViewCell->initWithReuseIdentifier(identifier))
    {
        //设置Frame范围
        listViewCell->setFrame(_rect);
        
        //设置为内存自动释放
        listViewCell->autorelease();
        return listViewCell;
    }
    
    //如果创建失败安全释放内存
    CC_SAFE_DELETE(listViewCell);
    return NULL;
}
 
void MyCell::initWithCell()
{
    //获得当前的宽度
    DSize _size = this->getFrame().size;
     
    //创建CALabel
    CALabel* test = CALabel::createWithCenter(DRect(_size.width*0.5,
        _size.height*0.5,
        _size.width*0.8,
        _size.height));
    test->setTextAlignment(CATextAlignmentCenter);
    test->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter);
    test->setFontSize(_px(40));
    test->setTag(100);
    this->addSubview(test);
}
 
void MyCell::cellBtnCallback(CAControl* btn, DPoint point)
{
    CCLog("MyCell::cellBtnCallback-->");
}
 
void MyCell::normalListViewCell()
{
    this->setBackgroundView(CAView::createWithColor(CAColor_white));
}
 
void MyCell::highlightedListViewCell()
{
    this->setBackgroundView(CAView::createWithColor(CAColor_yellow));
}
 
void MyCell::selectedListViewCell()
{
    this->setBackgroundView(CAView::createWithColor(CAColor_orange));
}
 
void MyCell::disabledListViewCell()
{
    this->setBackgroundView(CAView::createWithColor(CAColor_black));
}


CAListView 属性介绍

ListViewOrientation 

类型:CAListViewOrientation*

解释:listView的滚动方向。set/get{}。


ListViewDataSource

类型:CAListViewDataSource*

解释:添加数据代理。set/get{}。


ListViewDelegate    

类型:CAListViewDelegate*

解释:添加交互代理。set/get{}。


ListHeaderView      

类型:CAView*

解释:添加头部视图。set/get{}。


ListFooterView      

类型:CAView*

解释:添加尾部视图。set/get{}。


SeparatorColor     

类型:CAColor4B

解释:设置cell分割线的颜色。set/get{}。


ListHeaderHeight

类型:unsigned int

解释:设置头部视图的高度。set/get{}。


ListFooterHeight

类型:unsigned int

解释:设置尾部视图的高度。set/get{}。


SeparatorViewHeight

类型:unsigned int

解释:设置fell分割线的高度。set/get{}。


AllowsHeadAndFootHover  

类型:bool

解释:允许头和尾的悬停。set/get{}。


AllowsSelection   

类型:bool

解释:是否开启cell选择。is{}。


AllowsMultipleSelection    

类型:bool

解释:是否可以多选cell。is{}。


CAListView 方法介绍

virtual void setAllowsSelection(bool var);  

返回值:virtual void

参数:

类型
参数名
说明
bool var  

解释:是否可以多选cell


void setSelectAtIndex(unsigned int index);  

返回值:void

参数:

类型
参数名
说明
unsigned int index cell的索引值

解释:根据索引设置cell为选中状态


void setUnSelectAtIndex(unsigned int index);  

返回值:void

参数:

类型
参数名
说明
unsigned int index cell的索引值

解释:根据索引设置cell为未选中状态


virtual void setShowsScrollIndicators(bool var); 

返回值:virtual void

参数:

类型
参数名
说明
bool var 是否显示滚动条

解释:设置显示滚动条


CAListViewCell* dequeueReusableCellWithIdentifier(const char* reuseIdentifier);

返回值:CAListViewCell*

参数:

类型 参数名 说明
const char* reuseIdentifier 标识符

解释:可以重用单元标示符


CAListViewCell* cellForRowAtIndex(unsigned int index);

返回值:CAListViewCell*

参数:

类型 参数名 说明
unsigned int index cell的索引值

解释:通过cell索引获取Index


virtual void switchPCMode(bool var)

返回值:virtual void

参数:

类型 参数名 说明
bool var 开关

解释:开关PC模式


virtual bool ccTouchBegan(CATouch *pTouch, CAEvent *pEvent);

返回值:virtual bool

参数:

类型 参数名 说明
CATouch* pTouch 触摸传递对象
CAEvent* pEvent 此参数待定

解释:触摸事件开始时的回调函数


virtual void ccTouchMoved(CATouch *pTouch, CAEvent *pEvent);

返回值:virtual void

参数:

类型 参数名 说明
CATouch* pTouch 触摸传递对象
CAEvent* pEvent 此参数待定

解释:触摸事件中触点移动时的回调函数


virtual void ccTouchEnded(CATouch *pTouch, CAEvent *pEvent);

返回值:virtual void

参数:

类型 参数名 说明
CATouch* pTouch 触摸传递对象
CAEvent* pEvent 此参数待定

解释:触摸事件结束时的回调函数


virtual void ccTouchCancelled(CATouch *pTouch, CAEvent *pEvent);

返回值:virtual void

参数:

类型 参数名 说明
CATouch* pTouch 触摸传递对象
CAEvent* pEvent 此参数待定

解释:触摸非正常结束时的回调函数。(例如:电话或锁屏)


virtual void mouseMoved(CATouch* pTouch, CAEvent* pEvent);

返回值:virtual void

参数:

类型 参数名 说明
CATouch* pTouch 传递对象
CAEvent* pEvent 此参数待定

解释:鼠标移动


virtual void mouseMovedOutSide(CATouch* pTouch, CAEvent* pEvent);

返回值:virtual void

参数:

类型 参数名 说明
CATouch* pTouch 传递对象
CAEvent* pEvent 此参数待定

解释:鼠标移出


CAListViewDelegate 方法介绍

virtual void listViewDidSelectCellAtIndex(CAListView *listView, unsigned int index)        

返回值:virtual void

参数:

类型 参数名 说明
CAListView listView 当前的listView
unsigned int index cell的索引值

解释:选中cell时调用

        

virtual void listViewDidDeselectCellAtIndex(CAListView *listView, unsigned int index)        

返回值:virtual void

参数:

类型 参数名 说明
CAListView listView 当前的listView
unsigned int index cell的索引值

解释:取消选择cell时调用


CAListViewDataSource方法介绍

virtual unsigned int numberOfIndex(CAListView *listView)        

返回值:virtual unsigned int

参数:

类型 参数名 说明
CAListView listView 当前的listView

解释:cell的总数量


virtual unsigned int listViewHeightForIndex(CAListView *listView, unsigned int index)        

返回值:virtual unsigned int

参数:

类型 参数名 说明
CAListView listView 当前的listView
unsigned int index cell的索引值

解释:cell的高度


virtual CAListViewCell* listViewCellAtIndex(CAListView *listView, const DSize& cellSize, unsigned int index)       

返回值:virtual CAListViewCell*

参数:

类型 参数名 说明
CAListView listView 当前的listView
DSize cellSize cell的size
unsigned int index cell的索引值

解释:添加生成cell


virtual void listViewWillDisplayCellAtIndex(CAListView* table, CAListViewCell* cell, unsigned int index) ;

返回值:virtual void

参数:

类型 参数名 说明
CAListView listView 当前的listView
CAListViewCell cell 显示添加的cell
unsigned int index cell的索引值

解释:回调当前将要显示的CAListView


CAListViewCell 属性介绍

ContentView

类型:CAView*

解释:获得内容视图。get{}。


BackgroundView

类型:CAView*

解释:设置背景视图。set/get{}。


ReuseIdentifier

类型:std::string

解释:设置重用标识符。set/get{}。


Index

类型:unsigned int

解释:获得重用标识符。set/get{}。


ControlStateEffect

类型:bool

解释:设置控制状态效应。is/set{}。


AllowsSelected

类型:bool

解释:CAListViewCell是否可以选择。is/set{}。


CAListViewCell 方法介绍

static CAListViewCell* create(const std::string& reuseIdentifier);

返回值:static CAListViewCell*

参数:

类型 参数名 说明
std::string& reuseIdentifier 重用标识符

解释:创建,默认Frame为(0,0,0,0)


      

virtual bool initWithReuseIdentifier(const std::string& reuseIdentifier);

返回值:virtual bool

参数:

类型 参数名 说明
std::string& reuseIdentifier 重用标识符

解释:创建一个空CAListViewCell,默认Frame为(0,0,0,0)


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)