PPRevealSideViewControllerDemo(側滑效果),側滑蓋手機
初始的圖:
左滑,或劃的:
工程檔案:
MainViewController.h
#import <UIKit/UIKit.h>@interface MainViewController : UIViewController@end
MainViewContoller.m
#import "MainViewController.h"//加入標頭檔#import "PPRevealSideViewController.h"#import "leftViewController.h"#import "rightViewController.h"@implementation MainViewController- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. //設定背景色 self.view.backgroundColor= [UIColor orangeColor]; //隱藏導航條 self.navigationController.navigationBarHidden=YES; // 手勢左右滑動螢幕 UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleMoveFrom:)]; [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft]; [self.view addGestureRecognizer:swipeLeft]; UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleMoveFrom:)]; [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight]; [self.view addGestureRecognizer:swipeRight]; }// 滑動事件-(void)handleMoveFrom:(UISwipeGestureRecognizer *)swipe{ if(swipe.direction == UISwipeGestureRecognizerDirectionRight){ leftViewController *left = [[leftViewController alloc] init]; [self.revealSideViewController pushViewController:left onDirection:PPRevealSideDirectionLeft withOffset:50.0 animated:YES]; } if(swipe.direction == UISwipeGestureRecognizerDirectionLeft){ rightViewController *right = [[rightViewController alloc] init]; [self.revealSideViewController pushViewController:right onDirection:PPRevealSideDirectionRight withOffset:50.0 animated:YES]; }}
rightViewController.m
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. //設定標題 self.title=@"right"; //設定背景色 self.view.backgroundColor=[UIColor blueColor];}
leftViewController.m
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. //設定標題 self.title=@"left"; //設定背景色 self.view.backgroundColor=[UIColor redColor]; }