iOS實(shí)現(xiàn)簡(jiǎn)單的抽屜效果
說(shuō)到抽屜效果在iOS中比較有名的第三方類(lèi)庫(kù)就是PPRevealSideViewController。一說(shuō)到第三方類(lèi)庫(kù)就自然而然的想到我們的CocoaPods,本文用CocoaPods引入PPRevealSideViewController,然后在我們的工程中以代碼結(jié)合storyboard來(lái)做出抽屜效果。
一、在工程中用CocoaPods引入第三方插件PPRevealSideViewController.
(1).在終端中搜索PPRevealSideViewController的版本

(2).在Podfile中添加相應(yīng)的版本庫(kù)

(3).之后保存一下Podfile文件,然后執(zhí)行pod install即可
二、為我們的工程添加pch文件
因?yàn)橛玫氖荴Code6, 上面默認(rèn)是沒(méi)有pch文件的,如果我們想使用pch文件,需要手動(dòng)添加,添加步驟如下
1.在XCode6中是么有pch文件的,如下圖

2.創(chuàng)建pch文件


3.配置pch文件
(1)、找工程的Targets->Build Settings->Apple LLVM 6.0 - Language

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

三、使用PPRevealSideViewController來(lái)實(shí)現(xiàn)抽屜效果
當(dāng)然了首先在pch文件中引入我們的第三方類(lèi)庫(kù),然后使用即可
1.在storyboard拖出來(lái)我們要用的視圖控制器,點(diǎn)擊主界面上的按鈕會(huì)以抽屜的形式展示出導(dǎo)航頁(yè),然后在導(dǎo)航頁(yè)導(dǎo)航到各個(gè)界面,之后在從各個(gè)頁(yè)面回到主界面

2.在AppDelegate中初始化我們的PPRevealSideViewController并設(shè)置為啟動(dòng)頁(yè)面代碼如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//獲取主視圖的導(dǎo)航控制器
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"];
//新建PPRevealSideViewController,并設(shè)置根視圖(主頁(yè)面的導(dǎo)航視圖)
PPRevealSideViewController *sideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:vc];
sideViewController.fakeiOS7StatusBarColor = [UIColor whiteColor];
//把sideViewController設(shè)置成根視圖控制器
self.window.rootViewController = sideViewController;
[self.window makeKeyAndVisible];
return YES;
}
3.在主界面使用PPRevealSideViewController來(lái)推出導(dǎo)航頁(yè)
- (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.在導(dǎo)航頁(yè)點(diǎn)擊不同的按鈕使用PPRevealSideViewController跳轉(zhuǎn)到不同的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.各個(gè)頁(yè)面返回到主界面的代碼如下:
- (IBAction)tapPage:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
UIViewController *view = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"];
[self.revealSideViewController popViewControllerWithNewCenterController:view animated:YES];
}
四、到此效果實(shí)現(xiàn)完畢,下面是效果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助。
- iOS開(kāi)發(fā)之路--仿網(wǎng)易抽屜效果
- IOS中MMDrawerController第三方抽屜效果的基本使用示例
- iOS實(shí)現(xiàn)側(cè)拉欄抽屜效果
- IOS中Swift仿QQ最新版抽屜側(cè)滑和彈框視圖
- iOS實(shí)現(xiàn)左右拖動(dòng)抽屜效果
- IOS實(shí)現(xiàn)點(diǎn)擊滑動(dòng)抽屜效果
- ios仿側(cè)邊抽屜效果實(shí)現(xiàn)代碼
- iOS實(shí)現(xiàn)簡(jiǎn)單抽屜效果
- iOS實(shí)現(xiàn)簡(jiǎn)易抽屜效果、雙邊抽屜效果
- iOS簡(jiǎn)單抽屜效果的實(shí)現(xiàn)方法
相關(guān)文章
iOS 自定義狀態(tài)欄和導(dǎo)航欄詳細(xì)介紹
這篇文章主要介紹了iOS 自定義狀態(tài)欄和導(dǎo)航欄詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2016-11-11
IOS 開(kāi)發(fā)自定義條形ProgressView的實(shí)例
這篇文章主要介紹了IOS 開(kāi)發(fā)自定義條形ProgressView的實(shí)例的相關(guān)資料,希望開(kāi)發(fā)自己的條形進(jìn)度條的朋友可以參考下2016-10-10
iOS實(shí)現(xiàn)簡(jiǎn)單計(jì)算器小功能
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)簡(jiǎn)單計(jì)算器功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
IOS開(kāi)發(fā)仿微信右側(cè)彈出視圖實(shí)現(xiàn)
這篇文章主要介紹了IOS開(kāi)發(fā)仿微信右側(cè)彈出視圖實(shí)現(xiàn)的相關(guān)資料,希望通過(guò)本文能幫助到大家,讓大家實(shí)現(xiàn)這樣類(lèi)似的功能,需要的朋友可以參考下2017-10-10
基于iOS實(shí)現(xiàn)音樂(lè)震動(dòng)條效果
這篇文章主要為大家詳細(xì)介紹了基于iOS實(shí)現(xiàn)音樂(lè)震動(dòng)條效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
IOS 靜態(tài)庫(kù)打包流程簡(jiǎn)化詳細(xì)介紹
這篇文章主要介紹了IOS 靜態(tài)庫(kù)打包流程簡(jiǎn)化詳細(xì)介紹的相關(guān)資料,開(kāi)發(fā)好的靜態(tài)庫(kù)后需要手動(dòng)的合并.a文件,然后再拷貝相關(guān)的頭文件,接著把靜態(tài)庫(kù)和頭文件放在同一個(gè)文件里面打包發(fā)送給SDK的使用者,這里簡(jiǎn)化下流程,需要的朋友可以參考下2016-12-12

