iOS11新特性之在你的APP中使用LargeTitle

隨著WWDC17以及Apple 2017秋季新品發(fā)布會的召開,Apple也在9月20日正式推送了iOS 11的正式版。在iOS 11中,Apple也推出了全新的UI風格。

成都創(chuàng)新互聯(lián)公司是專業(yè)的達坂城網(wǎng)站建設(shè)公司,達坂城接單;提供成都網(wǎng)站建設(shè)、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進行達坂城網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團隊,希望更多企業(yè)前來合作!

iOS11新特性之在你的APP中使用LargeTitle 

UI風格

在iOS 11中,系統(tǒng)APP使用了這種UI風格。這種風格最明顯的變化就是使用了iOS 11的新特性--Large Title和新的SearchController。

Demo

GitHub: LargerTitleDemo

iOS11新特性之在你的APP中使用LargeTitle 

Large Title & Table View

設(shè)置Lager Title

APP全局使用Large Title

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 // Override point for customization after application launch.
 // 設(shè)置Large Title偏好為True。
 if (@available(iOS 11.0, *)) {
  [[UINavigationBar appearance] setPrefersLargeTitles:true];
 } else {
  // Fallback on earlier versions
 }
 return YES;
}

單個ViewController使用Larger Title

- (void)viewWillAppear:(BOOL)animated {
 [super viewWillAppear:animated];
 // 設(shè)置Large Title偏好為YES。
 if (@available(iOS 11.0, *)) {
  [self.navigationController.navigationBar setPrefersLargeTitles:YES];
 } else {
  // Fallback on earlier versions
 }
}

- (void)viewWillDisappear:(BOOL)animated {
 [super viewWillDisappear:animated];
 // 設(shè)置Large Title偏好為NO。
 if (@available(iOS 11.0, *)) {
  [self.navigationController.navigationBar setPrefersLargeTitles:NO];
 } else {
  // Fallback on earlier versions
 }
}

使用上述代碼設(shè)置后,即可開啟Large Title的顯示。

添加Table View

iOS11新特性之在你的APP中使用LargeTitle 

在StoryBoard添加TableView

在Xcode 9中,XIB和StoryBoard默認會添加 Safe Area(安全區(qū)) ,而添加在Controller的View上控件的約束也不再以supview為準,而是以Safe Area為準。

Safe Area是在iOS 9中添加的特性。如果你不需要使用Safe Area,或需要在舊版本的App中添加Safe Area,可以在XIB或StoryBoard的右側(cè)邊欄中“Show the File inspector”標簽下對“Use Safe Area Layout Guides”選項下進行勾選,以添加或刪除Safe Area。

iOS11新特性之在你的APP中使用LargeTitle 

添加Refresh Control

Refresh Control是系統(tǒng)的下拉刷新控件,配合Table View使用,以實現(xiàn)系統(tǒng)的下拉刷新效果。

UIRefreshControl *refreshControl = [[UIRefreshControl alloc]init];
[refreshControl addTarget:self action:@selector(beginRefresh:) forControlEvents:UIControlEventValueChanged];
if (@available(iOS 10.0, *)) {
 [self.tableView setRefreshControl:refreshControl];
} else {
 // Fallback on earlier versions
}

刷新完成調(diào)用 - (void)endRefreshing NS_AVAILABLE_IOS(6_0); 結(jié)束刷新狀態(tài)。

Search Controller

添加搜索欄

if (@available(iOS 11.0, *)) {
 UISearchController *searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
 self.navigationItem.searchController = searchController;
} else {
 // Fallback on earlier versions
}

關(guān)于 Search Controller 的使用在此不再贅述??蓞⒖脊俜絊ample Code Table Search with UISearchController

再說幾句

由于Large Title及一些API僅在iOS 11提供,所以在調(diào)用前均添加了判斷,以防止低版本系統(tǒng)調(diào)用高版本API造成應(yīng)用崩潰

if (@available(iOS 10.0, *)) {
 // Code...
} else {
 // Fallback on earlier versions
}

在實際開發(fā)中,在ViewController上添加TableView實現(xiàn)效果不夠理想,在滑動過程中有明顯卡頓。而直接使用TableViewController實現(xiàn)效果最為理想,滑動無卡頓現(xiàn)象。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

網(wǎng)站標題:iOS11新特性之在你的APP中使用LargeTitle
URL鏈接:http://bm7419.com/article32/pdhjpc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、外貿(mào)建站建站公司企業(yè)建站、搜索引擎優(yōu)化、微信公眾號

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)