当前位置:K88软件开发文章中心编程语言APP编程CrossApp → 文章内容

CANavigationController(导航控制器)

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-23 13:52:34

由 ?﹏???ζ???﹏﹏? 创建, 最后一次修改 2016-09-08 类说明CANavigationController是CAViewController的子类,它的作用是管理多个CAViewController,我们要明白的是CANavigationController是使用堆栈的方式管理的,即我们每往CANavigationController添加一个CAViewController,则进行一次堆栈的操作,每次移除则进行一次出栈操作。基类CAViewController, CANavigationBarDelegateCANavigationController 属性(点击查看方法介绍)属性说明NavigationBarHidden导航栏隐藏TouchMoved触摸移动NavigationBarBackGroundImage导航栏背面图像NavigationBarBackGroundColor导航栏背面颜色NavigationBarTitleColor导航栏标题颜色NavigationBarButtonColor导航栏按钮颜色CANavigationController 方法(点击查看方法介绍)方法说明initWithRootViewController使用CAViewController来初始化,这个是必须的replaceViewController替换栈顶的viewControllerpushViewController将新的viewController压入栈顶popViewControllerAnimated移除栈顶的viewControllerpopToRootViewControllerAnimated移除根的viewControllerpopFirstViewController移除第一个viewControllerpopViewControllerAtIndex根据索引值移除viewControllergetViewControllerAtIndex根据索引值获取viewControllergetBackViewController返回最后一个ViewControllergetViewControllerCount当前栈内viewController总数setNavigationBarHidden是否隐藏navigationBarupdateItem更新navigationBarItemccTouchBegan触摸事件开始时的回调函数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创建CANavigationBarItemstatic 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 = CABarVertica

[1] [2]  下一页


CANavigationController(导航控制器)