類說明
CANavigationController是CAViewController的子類,它的作用是管理多個(gè)CAViewController,我們要明白的是CANavigationController是使用堆棧的方式管理的,即我們每往CANavigationController添加一個(gè)CAViewController,則進(jìn)行一次堆棧的操作,每次移除則進(jìn)行一次出棧操作。
基類
CAViewController, CANavigationBarDelegate
CANavigationController 屬性(點(diǎn)擊查看方法介紹)
屬性 | 說明 |
NavigationBarHidden | 導(dǎo)航欄隱藏 |
TouchMoved | 觸摸移動(dòng) |
NavigationBarBackGroundImage | 導(dǎo)航欄背面圖像 |
NavigationBarBackGroundColor | 導(dǎo)航欄背面顏色 |
NavigationBarTitleColor | 導(dǎo)航欄標(biāo)題顏色 |
NavigationBarButtonColor | 導(dǎo)航欄按鈕顏色 |
CANavigationController 方法(點(diǎn)擊查看方法介紹)
方法 | 說明 |
initWithRootViewController | 使用CAViewController來初始化,這個(gè)是必須的 |
replaceViewController | 替換棧頂?shù)膙iewController |
pushViewController | 將新的viewController壓入棧頂 |
popViewControllerAnimated | 移除棧頂?shù)膙iewController |
popToRootViewControllerAnimated | 移除根的viewController |
popFirstViewController | 移除第一個(gè)viewController |
popViewControllerAtIndex | 根據(jù)索引值移除viewController |
getViewControllerAtIndex | 根據(jù)索引值獲取viewController |
getBackViewController | 返回最后一個(gè)ViewController |
getViewControllerCount | 當(dāng)前棧內(nèi)viewController總數(shù) |
setNavigationBarHidden | 是否隱藏navigationBar |
updateItem | 更新navigationBarItem |
ccTouchBegan | 觸摸事件開始時(shí)的回調(diào)函數(shù) |
ccTouchMoved | 觸摸事件中觸點(diǎn)移動(dòng)時(shí)的回調(diào)函數(shù) |
ccTouchEnded | 觸摸事件結(jié)束時(shí)的回調(diào)函數(shù) |
ccTouchCancelled | 觸摸非正常結(jié)束(例如:電話或鎖屏) |
isReachBoundaryLeft | 到左邊界 |
isReachBoundaryRight | 到右邊界 |
isReachBoundaryUp | 到上邊界 |
isReachBoundaryDown | 到下邊界 |
創(chuàng)建與初始化
bool RootWindow::init()
{
if (!CAWindow::init())
{
return false;
}
//創(chuàng)建Navigation
CANavigationController* _viewController = new CANavigationController();
//創(chuàng)建Navigation的第一個(gè)Controller
FirstViewController* first = new FirstViewController();
first->init();
//使用一個(gè)controller初始化Navigation(必須)
_viewController->initWithRootViewController(first);
//RootWindow加載Navigation
this->setRootViewController(_viewController);
//釋放內(nèi)存
first->release();
//釋放內(nèi)存
_viewController->release();
return true;
}
可控制樣式:barItem位置、標(biāo)題、左按鈕、右按鈕
bool RootWindow::init()
{
if (!CAWindow::init())
{
return false;
}
//創(chuàng)建Navigation
CANavigationController* _viewController = new CANavigationController();
//創(chuàng)建Navigation的第一個(gè)Controller
FirstViewController* first = new FirstViewController();
first->init();
//創(chuàng)建CANavigationBarItem并設(shè)置顯示標(biāo)題
CANavigationBarItem* nItem = CANavigationBarItem::create("First");
//創(chuàng)建左邊按鈕(右邊按鈕同理)
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);
//使用一個(gè)controller初始化Navigation(必須)
//CABarVerticalAlignmentBottom顯示在底部
_viewController->initWithRootViewController(first,CABarVerticalAlignmentBottom);
//RootWindow加載Navigation
this->setRootViewController(_viewController);
//釋放內(nèi)存
first->release();
//釋放內(nèi)存
_viewController->release();
return true;
}
主要了解:CABarButtonItem這個(gè)類的樣式
//根據(jù)title創(chuàng)建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);
/*
*移除棧頂?shù)膙iewController
*animated:是否播放動(dòng)畫
*/
CAViewController* popViewControllerAnimated(bool animated);
/*
*移除根的viewController
*animated:是否播放動(dòng)畫
*/
void popToRootViewControllerAnimated(bool animated);
/*
*移除第一個(gè)viewController
*animated:是否播放動(dòng)畫
*/
CAViewController* popFirstViewController();
/*
*根據(jù)索引值移除viewController
*animated:是否播放動(dòng)畫
*/
CAViewController* popViewControllerAtIndex(int index);
CANavigationController 屬性
類型:bool
解釋:導(dǎo)航欄隱藏。is{}。
類型:bool
解釋:觸摸移動(dòng)。is/set{}。
類型:CAImage*,
解釋:導(dǎo)航欄背面圖像。set/get{}。
類型:CAColor4B
解釋:導(dǎo)航欄背面顏色。set/get{}。
類型:CAColor4B
解釋:導(dǎo)航欄標(biāo)題顏色。set/get{}。
類型:CAColor4B
解釋:導(dǎo)航欄按鈕顏色。set/get{}。
CANavigationController 方法
virtual bool initWithRootViewController(CAViewController* viewController,CABarVerticalAlignment var = CABarVerticalAlignmentTop);
返回值:bool
參數(shù):
類型 | 參數(shù)名 | 說明 |
CAViewController* | viewController | 初始化CAViewController |
CABarVerticalAlignment | var = CABarVerticalAlignmentTop | CANavigationBar的現(xiàn)實(shí)樣式 |
解釋:使用CAViewController來初始化,這個(gè)是必須的
virtual void replaceViewController(CAViewController* viewController, bool animated);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說明 |
CAViewController* | viewController | 新的viewController |
bool | animated | 是否播放動(dòng)畫 |
解釋:替換棧頂?shù)膙iewController
virtual void pushViewController(CAViewController* viewController, bool animated);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說明 |
CAViewController* | viewController | 新的viewController |
bool | animated | 是否播放動(dòng)畫 |
解釋:將新的viewController壓入棧頂
CAViewController* popViewControllerAnimated(bool animated);
返回值:CAViewController*
參數(shù):
類型 | 參數(shù)名 | 說明 |
bool | animated | 是否播放動(dòng)畫 |
解釋:移除棧頂?shù)膙iewController
void popToRootViewControllerAnimated(bool animated);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說明 |
bool | animated | 是否播放動(dòng)畫 |
解釋:移除根的viewController
CAViewController* popFirstViewController();
返回值:CAViewController*
參數(shù):
解釋:移除第一個(gè)viewController
CAViewController* popViewControllerAtIndex(int index);
返回值:CAViewController*
參數(shù):
類型 | 參數(shù)名 | 說明 |
int | index | 移除第幾個(gè)viewController |
解釋:根據(jù)索引值移除viewController
CAViewController* getViewControllerAtIndex(int index);
返回值:CAViewController*
參數(shù):
類型 | 參數(shù)名 | 說明 |
int | index | 獲取第幾個(gè)viewController |
解釋:根據(jù)索引值獲取viewController
CAViewController* getBackViewController();
返回值:CAViewController*
參數(shù):
解釋:返回最后一個(gè)ViewController
inline unsigned long getViewControllerCount() ;
返回值:unsigned long
參數(shù):
解釋:當(dāng)前棧內(nèi)viewController總數(shù)
virtual void setNavigationBarHidden(bool hidden, bool animated);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說明 |
bool | hidden | 隱藏navigationBar |
bool | animated | 是否播放動(dòng)畫 |
解釋:是否隱藏navigationBar
void updateItem(CAViewController* viewController);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說明 |
CAViewController* | viewController | 更新navigationBarItem |
解釋:更新navigationBarItem
virtual bool ccTouchBegan(CATouch *pTouch, CAEvent *pEvent);
返回值:bool
參數(shù):
類型 | 參數(shù)名 | 說明 |
CATouch | *pTouch | 觸摸傳遞對(duì)象 |
CAEvent | *pEvent | 此參數(shù)待定 |
解釋:觸摸事件開始時(shí)的回調(diào)函數(shù)
virtual void ccTouchMoved(CATouch *pTouch, CAEvent *pEvent);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說明 |
CATouch | *pTouch | 觸摸傳遞對(duì)象 |
CAEvent | *pEvent | 此參數(shù)待定 |
解釋:觸摸事件中觸點(diǎn)移動(dòng)時(shí)的回調(diào)函數(shù)
virtual void ccTouchEnded(CATouch *pTouch, CAEvent *pEvent);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說明 |
CATouch | *pTouch | 觸摸傳遞對(duì)象 |
CAEvent | *pEvent | 此參數(shù)待定 |
解釋:觸摸事件結(jié)束時(shí)的回調(diào)函數(shù)
virtual void ccTouchCancelled(CATouch *pTouch, CAEvent *pEvent);
返回值:void
參數(shù):
類型 | 參數(shù)名 | 說明 |
CATouch | *pTouch | 觸摸傳遞對(duì)象 |
CAEvent | *pEvent | 此參數(shù)待定 |
解釋:觸摸非正常結(jié)束時(shí)的回調(diào)函數(shù)。(例如:電話或鎖屏)
virtual bool isReachBoundaryLeft();
返回值:virtual bool
參數(shù):
解釋:到左邊界
virtual bool isReachBoundaryRight();
返回值:virtual bool
參數(shù):
解釋:到右邊界
virtual bool isReachBoundaryUp();
返回值:virtual bool
參數(shù):
解釋:到上邊界
virtual bool isReachBoundaryDown();
返回值:virtual bool
參數(shù):
解釋:到下邊界
更多建議: