iOS應(yīng)用開(kāi)發(fā)實(shí)戰(zhàn)(10-13)-NavigationController & TabBarController

NavigationController & TabBarController都是界面控制的方式,在使用上感覺(jué)很近似,因此就把它們的筆記放在一起了。

Navigation Bar

Navigation Bar:最常用的界面跳轉(zhuǎn)控制方法之一
每個(gè)被管理的View Controller要提供:

  • 內(nèi)容
  • 導(dǎo)航欄標(biāo)題
  • 導(dǎo)航欄上額外按鍵
  • 工具欄(可選)按鍵

圖示

navigation_interface

navigation_interface_2x.png

nav_controllers_objects

nav_controllers_objects.jpg

結(jié)構(gòu):管理的VC,公共界面、Delegate

結(jié)構(gòu).jpg

Lifecycle

nav_controller_notifications.png
  • Tip:傳遞數(shù)據(jù)建議用Segue方法

在代碼中使用導(dǎo)航

創(chuàng)建

- (instancetype)initWithRootViewController:(UIViewController *)rootViewController; // Convenience method pushes the root view controller without animation.
- (instancetype)initWithNavigationBarClass:(nullable Class)navigationBarClass toolbarClass:(nullable Class)toolbarClass;
- (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers animated:(BOOL)animated ; // If animated is YES, then simulate a push or pop depending on whether the new top view controller was previously in the stack.

跳轉(zhuǎn)

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; // Uses a horizontal slide transition. Has no effect if the view controller is already in the stack.
- (nullable UIViewController *)popViewControllerAnimated:(BOOL)animated; // Returns the popped controller.
- (nullable NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated; // Pops until there's only a single view controller left on the stack. Returns the popped controllers.
- (nullable NSArray<__kindof UIViewController *> *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated; // Pops view controllers until the one specified is on top. Returns the popped controllers.
- (void)showViewController:(UIViewController *)vc sender:(nullable id)sender ; // Interpreted as pushViewController:animated:

設(shè)置和控制

@property(nullable, nonatomic, weak) id<UINavigationControllerDelegate> delegate;
@property(nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers; // The current view controller stack.
@property(nonatomic,readonly) UINavigationBar *navigationBar; // The navigation bar managed by the controller. Pushing, popping or setting navigation items on a managed navigation bar is not supported.
@property(null_resettable,nonatomic,readonly) UIToolbar ; // For use when presenting an action sheet.

界面定制

Demo:helloNavUI

helloNavUI.png

UINavigationBar

NavigationBar結(jié)構(gòu).jpg

UIBarButtonItem,UIBarButtonSystemItem

UIBarButtonItem.png

UITabBarController

一種分頁(yè)的方法

圖示

tabbar_compare.jpg

UITabBarController的結(jié)構(gòu)

結(jié)構(gòu).png

代碼

//創(chuàng)建
UITabBarController *vc =[[UITabBarController alloc]init];
vc.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"HOME" image:@"first" tag:0];

//管理
[self.tabBarController setViewControllers:@"FirstViewController" animated:YES];

//add
[self.view addSubview:vc];

//選中
vc.selectedViewController =vc;
vc.selectedIndex = 1;

界面定制

  • 中間拱起 :實(shí)質(zhì)上是另外加了個(gè)Button
  • 仿Path 4.x:實(shí)質(zhì)上是另外加了一個(gè)View
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容