你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS完成簡略的抽屜後果

iOS完成簡略的抽屜後果

編輯:IOS開發綜合

  說到抽屜後果在IOS中比擬著名的第三方類庫就是PPRevealSideViewController。一說到第三方類庫就天然而然的想到我們的CocoaPods,本文用CocoaPods引入PPRevealSideViewController,然後在我們的工程中以代碼聯合storyboard來做出抽屜後果。

一.在工程頂用CocoaPods引入第三方插件PPRevealSideViewController.

(1).在終端中搜刮PPRevealSideViewController的版本

(2).在Podfile中添加響應的版本庫

(3).以後保留一下Podfile文件,然後履行pod install便可

2、為我們的工程添加pch文件

由於用的是XCode6, 下面默許是沒有pch文件的,假如我們想應用pch文件,須要手動添加,添加步調以下

1.在XCode6中是麼有pch文件的,以下圖

2.創立pch文件

    

3.設置裝備擺設pch文件

(1)、找工程的Targets->Build Settings->Apple LLVM 6.0 - Language

(2)在Prefix Header上面的Debug和Release下添加$(SRCROOT)/工程名/pch文件,入下圖

3、應用PPRevealSideViewController來完成抽屜後果

固然了起首在pch文件中引入我們的第三方類庫,然後應用便可

1.在storyboard拖出來我們要用的視圖掌握器,點擊主界面上的按鈕會以抽屜的情勢展現出導航頁,然後在導航頁導航到各個界面,以後在從各個頁面回到主界面

2.在AppDelegate中初始化我們的PPRevealSideViewController並設置為啟動頁面代碼以下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Override point for customization after application launch.
  
  self.Window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  
  //獲得主視圖的導航掌握器
  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"];
  
  //新建PPRevealSideViewController,並設置根視圖(主頁面的導航視圖)
  PPRevealSideViewController *sideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:vc];
  
  sideViewController.fakeIOS7StatusBarColor = [UIColor whiteColor];
  
  //把sideViewController設置成根視圖掌握器
  self.Window.rootViewController = sideViewController;
  
  [self.window makeKeyAndVisible];
  
  return YES;
}

3.在主界面應用PPRevealSideViewController來推出導航頁

- (IBAction)tapItem:(id)sender {
  
  UIStoryboard *storybaord = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  UITableViewController *table = [storybaord instantiateViewControllerWithIdentifier:@"CustomViewViewController"];
  [self.revealSideViewController pushViewController:table onDirection:PPRevealSideDirectionLeft animated:YES];
}

4.在導航頁點擊分歧的按鈕應用PPRevealSideViewController跳轉到分歧的controller

- (IBAction)tap1:(id)sender {
   UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  UIViewController *one = [storyboard instantiateViewControllerWithIdentifier:@"one"];
  [self.revealSideViewController popViewControllerWithNewCenterController:one animated:YES];
}

- (IBAction)tap2:(id)sender {
  
  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  UIViewController *one = [storyboard instantiateViewControllerWithIdentifier:@"two"];
  [self.revealSideViewController popViewControllerWithNewCenterController:one animated:YES];
  
}

- (IBAction)tap3:(id)sender {
  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  UIViewController *one = [storyboard instantiateViewControllerWithIdentifier:@"three"];
  [self.revealSideViewController popViewControllerWithNewCenterController:one animated:YES];
}

- (IBAction)tap4:(id)sender {
  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  UIViewController *one = [storyboard instantiateViewControllerWithIdentifier:@"four"];
  [self.revealSideViewController popViewControllerWithNewCenterController:one animated:YES];
}

5.各個頁面前往到主界面的代碼以下:

- (IBAction)tapPage:(id)sender {
  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
  
  UIViewController *view = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"];
  
  [self.revealSideViewController popViewControllerWithNewCenterController:view animated:YES];
}

四.到此後果完成終了,上面是後果圖:

以上就是本文的全體內容,願望對年夜家的進修有所贊助。

【iOS完成簡略的抽屜後果】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved