CANavigationController(导航控制器)

类说明

CANavigationController是CAViewController的子类,它的作用是管理多个CAViewController,我们要明白的是CANavigationController是使用堆栈的方式管理的,即我们每往CANavigationController添加一个CAViewController,则进行一次堆栈的操作,每次移除则进行一次出栈操作。

基类

CAViewController, CANavigationBarDelegate

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

属性说明
NavigationBarHidden导航栏隐藏
TouchMoved触摸移动
NavigationBarBackGroundImage导航栏背面图像
NavigationBarBackGroundColor导航栏背面颜色
NavigationBarTitleColor导航栏标题颜色
NavigationBarButtonColor导航栏按钮颜色

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

方法
说明
initWithRootViewController使用CAViewController来初始化,这个是必须的
replaceViewController替换栈顶的viewController
pushViewController将新的viewController压入栈顶
popViewControllerAnimated移除栈顶的viewController
popToRootViewControllerAnimated移除根的viewController
popFirstViewController移除第一个viewController
popViewControllerAtIndex根据索引值移除viewController
getViewControllerAtIndex根据索引值获取viewController
getBackViewController返回最后一个ViewController
getViewControllerCount当前栈内viewController总数
setNavigationBarHidden是否隐藏navigationBar
updateItem更新navigationBarItem
ccTouchBegan触摸事件开始时的回调函数
ccTouchMoved触摸事件中触点移动时的回调函数
ccTouchEnded触摸事件结束时的回调函数
ccTouchCancelled触摸非正常结束(例如:电话或锁屏)
isReachBoundaryLeft到左边界
isReachBoundaryRight到右边界
isReachBoundaryUp到上边界
isReachBoundaryDown到下边界


创建与初始化

bool RootWindow::init()
{
    if (!CAWindow::init())
    {
        return false;
    }
     
    //创建Navigation
    CANavigationController* _viewController = new CANavigationController();
    
    //创建Navigation的第一个Controller
    FirstViewController* first = new FirstViewController();
      first->init();
     
    //使用一个controller初始化Navigation(必须)
    _viewController->initWithRootViewController(first);
     
    //RootWindow加载Navigation
    this->setRootViewController(_viewController);
    
    //释放内存
    first->release();
    
    //释放内存
    _viewController->release();
    return true;
}

样式属性

可控制样式:barItem位置、标题、左按钮、右按钮

bool RootWindow::init()
{
    if (!CAWindow::init())
    {
        return false;
    }
     
    //创建Navigation
    CANavigationController* _viewController = new CANavigationController();
     
    //创建Navigation的第一个Controller
    FirstViewController* first = new FirstViewController();
      first->init();
     
    //创建CANavigationBarItem并设置显示标题
    CANavigationBarItem* nItem = CANavigationBarItem::create("First");
     
    //创建左边按钮(右边按钮同理)
    CABarButtonItem* leftBtn = CABarButtonItem::create("", CAImage::create("source_material/btn_left_white.png"), CAImage::create("source_material/btn_left_blue.png"));
    
    //将leftBtn添加到CANavigationBarItem
    nItem->addLeftButtonItem(leftBtn);
     
    //将CANavigationBarItem添加到FirstViewController
    first->setNavigationBarItem(nItem);
     
    //使用一个controller初始化Navigation(必须)
    //CABarVerticalAlignmentBottom显示在底部
    _viewController->initWithRootViewController(first,CABarVerticalAlignmentBottom);
    
    //RootWindow加载Navigation
    this->setRootViewController(_viewController);
    
    //释放内存
    first->release();
    
    //释放内存
    _viewController->release();
    return true;
}


主要了解:CABarButtonItem这个类的样式

//根据title创建CANavigationBarItem
static CANavigationBarItem* create(const std::string& title);
 
//添加左边按钮
void addLeftButtonItem(CABarButtonItem* item);
 
//添加邮编按钮
void addRightButtonItem(CABarButtonItem* item);

管理

初始化

virtual bool initWithRootViewController(CAViewController* viewController,CABarVerticalAlignment var = CABarVerticalAlignmentTop);

替换

virtual void replaceViewController(CAViewController* viewController, bool animated);

增加

virtual void pushViewController(CAViewController* viewController, bool animated);

移除

  /*
    *移除栈顶的viewController
    *animated:是否播放动画
    */
    CAViewController* popViewControllerAnimated(bool animated);
     
    /*
    *移除根的viewController
    *animated:是否播放动画
    */
    void popToRootViewControllerAnimated(bool animated);
     
    /*
    *移除第一个viewController
    *animated:是否播放动画
    */
    CAViewController* popFirstViewController();
     
    /*
    *根据索引值移除viewController
    *animated:是否播放动画
    */
    CAViewController* popViewControllerAtIndex(int index);

CANavigationController 属性

NavigationBarHidden

类型:bool

解释:导航栏隐藏。is{}。

 TouchMoved

类型:bool

解释:触摸移动。is/set{}。    

NavigationBarBackGroundImage

类型:CAImage*,

解释:导航栏背面图像。set/get{}。

NavigationBarBackGroundColor

类型:CAColor4B

解释:导航栏背面颜色。set/get{}。

NavigationBarTitleColor

类型:CAColor4B

解释:导航栏标题颜色。set/get{}。

NavigationBarButtonColor

类型:CAColor4B

解释:导航栏按钮颜色。set/get{}。

CANavigationController 方法

virtual bool initWithRootViewController(CAViewController* viewController,CABarVerticalAlignment var = CABarVerticalAlignmentTop);

返回值:bool

参数:

类型参数名说明
CAViewController*viewController初始化CAViewController
CABarVerticalAlignmentvar = CABarVerticalAlignmentTopCANavigationBar的现实样式

解释:使用CAViewController来初始化,这个是必须的

                                      

virtual void replaceViewController(CAViewController* viewController, bool animated);

返回值:void

参数:

类型参数名说明
CAViewController*viewController新的viewController
boolanimated是否播放动画

解释:替换栈顶的viewController

      

virtual void pushViewController(CAViewController* viewController, bool animated);

返回值:void

参数:

类型参数名说明
CAViewController*viewController新的viewController
boolanimated是否播放动画

解释:将新的viewController压入栈顶

CAViewController* popViewControllerAnimated(bool animated);

返回值:CAViewController*

参数:

类型参数名说明
boolanimated是否播放动画

解释:移除栈顶的viewController

void popToRootViewControllerAnimated(bool animated);

返回值:void

参数:

类型参数名说明
boolanimated是否播放动画

解释:移除根的viewController

CAViewController* popFirstViewController();

返回值:CAViewController*

参数:

解释:移除第一个viewController

CAViewController* popViewControllerAtIndex(int index);

返回值:CAViewController*

参数:

类型参数名说明
intindex移除第几个viewController

解释:根据索引值移除viewController

CAViewController* getViewControllerAtIndex(int index);

返回值:CAViewController*

参数:

类型参数名说明
intindex获取第几个viewController

解释:根据索引值获取viewController

CAViewController* getBackViewController();

返回值:CAViewController*

参数:

解释:返回最后一个ViewController

inline unsigned long getViewControllerCount() ;

返回值:unsigned long

参数:

解释:当前栈内viewController总数

virtual void setNavigationBarHidden(bool hidden, bool animated);

返回值:void

参数:

类型参数名说明
boolhidden隐藏navigationBar
boolanimated是否播放动画

解释:是否隐藏navigationBar

void updateItem(CAViewController* viewController);

返回值:void

参数:

类型参数名说明
CAViewController*viewController更新navigationBarItem

解释:更新navigationBarItem

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

返回值:bool

参数:

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

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

   

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

返回值:void

参数:

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

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

  

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

返回值:void

参数:

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

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

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

返回值:void

参数:

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

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

virtual bool isReachBoundaryLeft();

返回值:virtual bool

参数:

解释:到左边界

virtual bool isReachBoundaryRight();

返回值:virtual bool

参数:

解释:到右边界

virtual bool isReachBoundaryUp();

返回值:virtual bool

参数:

解释:到上边界

virtual bool isReachBoundaryDown();

返回值:virtual bool

参数:

解释:到下边界

作者:admin,如若转载,请注明出处:https://www.web176.com/crossapp/10170.html

(0)
打赏 支付宝 支付宝 微信 微信
adminadmin
上一篇 2023年2月21日
下一篇 2023年2月21日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注