iOS 11 導覽列變化

來源:互聯網
上載者:User
一、prefersLargeTitles屬性

iOS11 UINavigationBar新添加的prefersLargeTitles屬性 1、prefersLargeTitles

/// When set to YES, the navigation bar will use a larger out-of-line title view when requested by the current navigation item. To specify when the large out-of-line title view appears, see UINavigationItem.largeTitleDisplayMode. Defaults to NO.@property (nonatomic, readwrite, assign) BOOL prefersLargeTitles UI_APPEARANCE_SELECTOR API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);

大標題,預設為false,當設定為true時,navigation bar會顯示大標題,標題顯示在左邊,如果頁面有scrollview控制項或父控制項為這個時,當向上滑動頁面,標題會變小直到跟之前顯示一樣,同時標題位置也會發生變化。 當這個屬性設定為NO的時候,navigation bar 的高度為44(iPhone X除外); 當這個屬性設定為NO的時候,navigation bar 的高度為96(iPhone X除外); 2、largeTitleDisplayMode

/// When UINavigationBar.prefersLargeTitles=YES, this property controls when the larger out-of-line title is displayed. If prefersLargeTitles=NO, this property has no effect. The default value is Automatic.@property (nonatomic, readwrite, assign) UINavigationItemLargeTitleDisplayMode largeTitleDisplayMode API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);

該屬性包含四個值

typedef NS_ENUM(NSInteger, UINavigationItemLargeTitleDisplayMode) {    /// Automatically use the large out-of-line title based on the state of the previous item in the navigation bar. An item with largeTitleDisplayMode=Automatic will show or hide the large title based on the request of the previous navigation item. If the first item pushed is set to Automatic, then it will show the large title if the navigation bar has prefersLargeTitles=YES.    UINavigationItemLargeTitleDisplayModeAutomatic,    /// Always use a larger title when this item is top most.    UINavigationItemLargeTitleDisplayModeAlways,    /// Never use a larger title when this item is top most.    UINavigationItemLargeTitleDisplayModeNever,} NS_SWIFT_NAME(UINavigationItem.LargeTitleDisplayMode);

largeTitleDisplayMode是配合prefersLargeTitles屬性的,只要當prefersLargeTitles為YES時才生效,largeTitleDisplayMode有三個模式: UINavigationItemLargeTitleDisplayModeAutomatic:自動顯示大標題或小標題。用我的話來說:初始時是大標題,當滑動使大標題隱藏時顯示小標題。 UINavigationItemLargeTitleDisplayModeAlways:總是顯示大標題。 UINavigationItemLargeTitleDisplayModeNever:總是顯示小標題。 3、largeTitleTextAttributes

/* You may specify the font, text color, and shadow properties for the large title in the text attributes dictionary, using the keys found in NSAttributedString.h. */@property(nullable, nonatomic, copy) NSDictionary<NSAttributedStringKey, id> *largeTitleTextAttributes UI_APPEARANCE_SELECTOR API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);

設定標題屬性(顏色,字型大小)

[self.navigationController.navigationBar setLargeTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,[UIFont systemFontOfSize:18.0f],NSFontAttributeName,nil]];
二、導覽列視圖的位置變更 1、iOS 11 以前


navigationBarButton則直接添加在navigationBar上面 2、iOS 11 以後


titleView直接加在_UINavigationBarContentView上,UIBarButtonItem則添加在_UIButtonBarStackView上面,_UIButtonBarStackView則添加在_UINavigationBarContentView上面,最後添加到UINavigationBar上面。 三、UISearchController

UISearchController控制項是iOS 8時引入的,經常配合UITableView的tableHeaderView使用,在iOS 11 UISearchController使用在navigationItem添加了兩個屬性 。

// A view controller that will be shown inside of a navigation controller can assign a UISearchController to this property to display the search controller’s search bar in its containing navigation controller’s navigation bar.@property (nonatomic, retain, nullable) UISearchController *searchController API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);// If this property is true (the default), the searchController’s search bar will hide as the user scrolls in the top view controller’s scroll view. If false, the search bar will remain visible and pinned underneath the navigation bar.@property (nonatomic) BOOL hidesSearchBarWhenScrolling API_AVAILABLE(ios(11.0)) API_UNAVAILABLE(tvos);

使用方式變換:
UISearchController *searchC = [[UISearchController alloc]initWithSearchResultsController:nil];

if (@available(iOS 11.0, *)) {    self.navigationItem.searchController = searchC;    self.navigationItem.hidesSearchBarWhenScrolling = NO;} else {    self.tableView.tableHeaderView = searchC.searchBar;}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.