IOS 頁面跳轉(zhuǎn)方法總結(jié)

嘗試列出所有的頁面跳轉(zhuǎn)方法,有疏漏的歡迎補充。

1.UINavigationController - push & pop (常用)

在AppDelegate didFinishLaunchingWithOptions中指定首頁面
//myView一個btn 點擊后調(diào)用push
UIViewController *myViewController = [[MyViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];

在指定的myViewController中,可調(diào)用

[self.navigationController pushViewController:self.secondVC animated:YES];
來完成頁面跳轉(zhuǎn)

同樣宝踪,在跳轉(zhuǎn)完成后的頁面中蔼紧,可以調(diào)用

[self.navigationController popViewControllerAnimated:YES];

來回到上一個頁面俭嘁。

2.UITabBarController
微信的頁面就是一個UITabBarController 和 NavigationController 合用的例子

Paste_Image.png


//1.創(chuàng)建Window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];

//a.初始化一個tabBar控制器
UITabBarController *tb=[[UITabBarController alloc]init];
//設(shè)置控制器為Window的根控制器
self.window.rootViewController=tb;

//b.創(chuàng)建子控制器
MyViewController *c1=[[MyViewController alloc]init];

UINavigationController *nc1 = [[UINavigationController alloc] initWithRootViewController:c1];
nc1.view.backgroundColor=[UIColor grayColor];
nc1.view.backgroundColor=[UIColor greenColor];
nc1.tabBarItem.title=@"消息";
nc1.tabBarItem.image=[UIImage imageNamed:@"tab_recent_nor"];
nc1.tabBarItem.badgeValue=@"123";

MyViewController *c2=[[MyViewController alloc]init];

UINavigationController *nc2 = [[UINavigationController alloc] initWithRootViewController:c2];
nc2.view.backgroundColor=[UIColor brownColor];
nc2.tabBarItem.title=@"聯(lián)系人";
nc2.tabBarItem.image=[UIImage imageNamed:@"tab_buddy_nor"];

MyViewController *c3=[[MyViewController alloc]init];

UINavigationController *nc3 = [[UINavigationController alloc] initWithRootViewController:c3];
nc3.tabBarItem.title=@"動態(tài)";
nc3.tabBarItem.image=[UIImage imageNamed:@"tab_qworld_nor"];

MyViewController *c4=[[MyViewController alloc]init];

UINavigationController *nc4 = [[UINavigationController alloc] initWithRootViewController:c4];
nc4.tabBarItem.title=@"設(shè)置";
nc4.tabBarItem.image=[UIImage imageNamed:@"tab_me_nor"];
   

//c.添加子控制器到ITabBarController中
//c.1第一種方式
//[tb addChildViewController:nc1];
//[tb addChildViewController:nc2];

//c.2第二種方式
tb.viewControllers=@[nc1,nc2,nc3,nc4];


//2.設(shè)置Window為主窗口并顯示出來
[self.window makeKeyAndVisible];


3.(Modal)UIViewController - presentView

UIViewController或者其子類的方法中調(diào)用

[self presentViewController:self.secondVC animated:YES completion:nil];

默認從下至上彈出一個VC來展示拨拓。

[self dismissViewControllerAnimated:YES completion:nil];

關(guān)閉彈出的VC

4.addChildViewController

@interface UIViewController (UIContainerViewControllerProtectedMethods)

// An array of children view controllers. This array does not include any presented view controllers.
@property(nonatomic,readonly) NSArray<__kindof UIViewController *> *childViewControllers NS_AVAILABLE_IOS(5_0);

/*
  If the child controller has a different parent controller, it will first be removed from its current parent
  by calling removeFromParentViewController. If this method is overridden then the super implementation must
  be called.
*/
- (void)addChildViewController:(UIViewController *)childController NS_AVAILABLE_IOS(5_0);

/*
 This method can be used to transition between sibling child view controllers.
*/
- (void)transitionFromViewController:(UIViewController *)fromViewController 
toViewController:(UIViewController *)toViewController 
duration:(NSTimeInterval)duration 
options:(UIViewAnimationOptions)options 
animations:(void (^ __nullable)(void))animations 
completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(5_0);

期待補充

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末肴颊,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子渣磷,更是在濱河造成了極大的恐慌婿着,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,204評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件醋界,死亡現(xiàn)場離奇詭異竟宋,居然都是意外死亡,警方通過查閱死者的電腦和手機形纺,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,091評論 3 395
  • 文/潘曉璐 我一進店門丘侠,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人逐样,你說我怎么就攤上這事蜗字。” “怎么了脂新?”我有些...
    開封第一講書人閱讀 164,548評論 0 354
  • 文/不壞的土叔 我叫張陵挪捕,是天一觀的道長。 經(jīng)常有香客問我戏羽,道長担神,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,657評論 1 293
  • 正文 為了忘掉前任始花,我火速辦了婚禮,結(jié)果婚禮上孩锡,老公的妹妹穿的比我還像新娘酷宵。我一直安慰自己,他們只是感情好躬窜,可當我...
    茶點故事閱讀 67,689評論 6 392
  • 文/花漫 我一把揭開白布浇垦。 她就那樣靜靜地躺著,像睡著了一般荣挨。 火紅的嫁衣襯著肌膚如雪男韧。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,554評論 1 305
  • 那天默垄,我揣著相機與錄音此虑,去河邊找鬼。 笑死口锭,一個胖子當著我的面吹牛朦前,可吹牛的內(nèi)容都是我干的介杆。 我是一名探鬼主播,決...
    沈念sama閱讀 40,302評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼韭寸,長吁一口氣:“原來是場噩夢啊……” “哼春哨!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起恩伺,我...
    開封第一講書人閱讀 39,216評論 0 276
  • 序言:老撾萬榮一對情侶失蹤赴背,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后晶渠,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體癞尚,經(jīng)...
    沈念sama閱讀 45,661評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,851評論 3 336
  • 正文 我和宋清朗相戀三年乱陡,在試婚紗的時候發(fā)現(xiàn)自己被綠了浇揩。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,977評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡憨颠,死狀恐怖胳徽,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情爽彤,我是刑警寧澤养盗,帶...
    沈念sama閱讀 35,697評論 5 347
  • 正文 年R本政府宣布,位于F島的核電站适篙,受9級特大地震影響往核,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜嚷节,卻給世界環(huán)境...
    茶點故事閱讀 41,306評論 3 330
  • 文/蒙蒙 一聂儒、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧硫痰,春花似錦衩婚、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,898評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至缓屠,卻和暖如春奇昙,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背敌完。 一陣腳步聲響...
    開封第一講書人閱讀 33,019評論 1 270
  • 我被黑心中介騙來泰國打工储耐, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人蠢挡。 一個月前我還...
    沈念sama閱讀 48,138評論 3 370
  • 正文 我出身青樓弧岳,卻偏偏與公主長得像凳忙,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子禽炬,可洞房花燭夜當晚...
    茶點故事閱讀 44,927評論 2 355

推薦閱讀更多精彩內(nèi)容