iOS開發-UI (六)Navigation

来源:http://www.cnblogs.com/fcug/archive/2017/01/19/6308951.html
-Advertisement-
Play Games

知識點: 1.UINavigationController 2.UINavigationItem 3.UINavigationBar 4.UINavigationController視圖切換 UINavigationController 1.什麼是導航控制器 作用:管理視圖控制器 2.UINavig ...


知識點:

1.UINavigationController

2.UINavigationItem

3.UINavigationBar

4.UINavigationController視圖切換

 

========================

UINavigationController

    1.什麼是導航控制器

作用:管理視圖控制器

 

    2.UINavigationController對象創建

      1)初始化方式

- (id)initWithRootViewController:(UIViewController *)rootViewController

 

      2)UINavigationController組成:

(1)navigationBar(高度44)

(2)customContent  — 有自定義的ViewController提供

(3)navigationToolbar(高度44)

 

 

    3.通過UINavigationController對象切換視圖

      1)將視圖控制器壓入導航控制器的棧容器中

- (void)pushViewController:(UIViewController *)viewController 

  animated:(BOOL)animated

      2)將視圖控制器從導航控制器中彈出

- (UIViewController *)popViewControllerAnimated:(BOOL)animated

  

========================

UINavigationItem

 

UINavigationItem包含了:

(1)backBarButtonItem(由上一級ctl的屬性決定)

(2)title/titleView(當前ctl)

(3)rightBarButtonItem(當前ctl)

(4)leftBarButtonItem(當前ctl)

 

 

    1.UINavigationItem和UIViewController關係

navigationItem是UIViewController的一個屬性

這個屬性是為UINavigationController服務的

 

 

    2.創建UIBarButtonItem

  1)創建系統自帶的UIBarButtonSystemItem

      - (id)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem 

      target:(id)target 

  action:(SEL)action;

 

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(btnAction)];

      2)文字UIBarButtonItem的創建方式

- (id)initWithTitle:(NSString *)title

      style:(UIBarButtonItemStyle)style

    target:(id)target

    action:(SEL)action

 

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem new];

 

      3)圖片UIBarButtonItem的創建方式

- (id)initWithImage:(UIImage *)image 

      style:(UIBarButtonItemStyle)style

    target:(id)target

    action:(SEL)action

 

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"refresh_30"] style:UIBarButtonItemStylePlain target:nil action:nil];

 

      3)如何將UIBarButtonItem加入到導航的左邊和右邊

@property (nonatomic, retain) UIBarButtonItem *leftBarButtonItem

@property (nonatomic, retain) UIBarButtonItem *rightBarButtonItem

@property (nonatomic, retain) UIBarButtonItem *backBarButtonItem

 

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:b];

 

    3.定製UIBarButtonItem

 

    4.定製導航中間的titleView

self.navigationItem.title = @"控制器2";

 

    5.定製backBarButtonItem

      註意:設置當前控制器的backBarButtonItem需要在下一個控制器中才能顯示

 

 

========================

UINavigationBar

    1.如何往UINavigationBar貼圖

      設置背景圖片

      - (void)setBackgroundImage:(UIImage *)backgroundImage

    forBarMetrics:(UIBarMetrics)barMetrics

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"1.png"] forBarMetrics:UIBarMetricsDefault];

 

    2.如何設置UINavigationBar設置顏色

      @property (nonatomic, retain) UIColor *tintColor

      @property (nonatomic, retain) UIColor *barTintColor

 

    3.如何設置透明顏色

      1)設置UINavigationBar的樣式

      @property (nonatomic, assign) UIBarStyle barStyle

   self.navigationController.navigationBar.barStyle= UIBarStyleBlack;

 

      2)是否透明

@property (nonatomic, assign, getter=isTranslucent) BOOL translucent

 

//獲取管理當前視圖控制器的導航控制器(如果這個視圖控制器沒有受到導航控制器管理,此方法會返回空指針)

    //設置導航欄為不透明,坐標點會自動下移64個單位

    self.navigationController.navigationBar.translucent = NO;

 

      3)改變導航欄的顏色

@property(nonatomic,retain) UIColor *barTintColor 

 

//設置背景色

    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];

 

    4.如何隱藏UINavigationBar

      1)不帶動畫隱藏

      @property (nonatomic, getter=isNavigationBarHidden) BOOL  navigationBarHidden

 

//顯示

    self.navigationController.navigationBarHidden = NO;

 

      2)帶動畫隱藏

- (void) setNavigationBarHidden:(BOOL)navigationBarHidden 

      animated:(BOOL)animated

      [self.navigationController setNavigationBarHidden:YES animated:YES];

 

========================

UINavigationController視圖切換

    1.獲取導航控制器中的視圖數組

@property (nonatomic, copy) NSArray *viewControllers

 

    2.將視圖控制器壓入導航控制器的棧容器中

- (void)pushViewController:(UIViewController *)viewController 

  animated:(BOOL)animated

 

//視圖控制器入棧

    [self.navigationController pushViewController:ctlA animated:YES];

 

    3.將視圖控制器從導航控制器中彈出

- (UIViewController *)popViewControllerAnimated:(BOOL)animated

 

    4.切換至指定的視圖控制器(該控制器必須在當前導航控制器中的棧中)

- (NSArray *)popToViewController:(UIViewController *)viewController

                                animated:(BOOL)animated

    5.回到根視圖控制器

     - (NSArray *)popToRootViewControllerAnimated:(BOOL)animated

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 最近剛做完一個移動端的項目,產品之無敵,過程之艱辛,我就不多說了,記錄下在這個項目中遇到的問題,以防萬一,雖然這些可能都是已經被N多前輩解決掉了的問題,也放在這裡,算是為自己漫漫前端路鋪了一顆小石子兒吧,也在文末留下自己未能解決的疑問,希望看到的朋友能解惑。 都知道做移動端的開發,在電腦上調試好了的 ...
  • 項目中經常用到三角形,現在給大家講下用純CSS寫的下三角實心圖形 其他方向的三角圖形自己調樣式哈,舉一反三,不要這麼懶嘛,自己弄才會進步。 ...
  • 這是翻譯的一篇文章,原文是: "3 New CSS Features to Learn in 2017" ,翻譯的不是很好,如有疑問歡迎指出。 新的一年,我們有一系列新的東西要學習。儘管CSS有很多新的特性,但有三個特性令我最激動併進行學習。 1. Feature Queries(特性查詢) 在這之 ...
  • 今天學習的新內容是側滑導航欄,我想大家肯定都比較熟悉了,因為這個效果在qq裡面也有,最近一直跟室友們玩的游戲是快速讓自己的頭像的點贊量上千。當然我的效果跟qq是沒有辦法比的,因為那裡面的功能是在是太強大了。下麵我來展示一下我做的效果截圖。 我做的界面有點醜,但是對比之前已經是有了很大的改觀了。想做這 ...
  • 解決的辦法:在Build Settings >Aplle LLVM8.0 - Language - Objectibe-C >Weak Reference In Manual Retain Release 設置為YES。 ...
  • let systemFont = UIFont.systemFontOfSize(14)let otherFont = UIFont(descriptor: systemFont.fontDescriptor(), size: 16)以下是錯誤形式:let systemFont = UIFont.s... ...
  • 介紹 好久沒有寫博客啦,最近在接近新年了,年前的工作都要收尾,所以特別忙,周末抽空寫了個通用的載入view,寫篇博客分享出來。 功能 1、顯示載入視圖,載入失敗的時候顯示載入失敗視圖,數據為空時顯示數據為空視圖,支持為失敗視圖設置點擊事件重新載入數據。 2、支持個性化設置,自定義設置 載入、失敗、空 ...
  • 今天來到打開昨天的項目運行正常,然後改動了一點代碼編譯報錯: 把代碼改動的地方恢復還是一隻再報這個錯誤,想到了iOS開發中遇到莫名的錯誤第一步就是clean一下,重新編譯一下項目。Android Studio更好,直接有Rebuild功能(Build選項裡面),重新build項目後,錯誤消失,正常運 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...