【讀書筆記】側滑效果,讀書筆記側滑

來源:互聯網
上載者:User

【讀書筆記】側滑效果,讀書筆記側滑

一,。

二,工程圖。

三,代碼。

AppDelegate.h

#import <UIKit/UIKit.h>//加入標頭檔#import "PPRevealSideViewController.h"@interface AppDelegate : UIResponder <UIApplicationDelegate,PPRevealSideViewControllerDelegate>@property (strong, nonatomic) UIWindow *window;@end

 

AppDelegate.m

#import "AppDelegate.h"#import "MainViewController.h"@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];    // Override point for customization after application launch.        MainViewController *main = [[MainViewController alloc] init];    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:main];    PPRevealSideViewController *revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav];    revealSideViewController.delegate = self;    self.window.rootViewController = revealSideViewController;        self.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];    return YES;}

 

MainViewController.h

#import <UIKit/UIKit.h>@interface MainViewController : UIViewController@end

 

MainViewController.m

#import "MainViewController.h"//加入標頭檔#import "PPRevealSideViewController.h"#import "leftViewController.h"#import "rightViewController.h"@interface MainViewController ()@end@implementation MainViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (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];     }}- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}

 

rightViewController.h

#import <UIKit/UIKit.h>@interface rightViewController : UIViewController@end

 

rightViewController.m

#import "rightViewController.h"@interface rightViewController ()@end@implementation rightViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.        //設定標題    self.title=@"right";    //設定背景色    self.view.backgroundColor=[UIColor blueColor];}- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}

 

leftViewController.h

#import <UIKit/UIKit.h>@interface leftViewController : UIViewController@end

 

leftViewController.m

#import "leftViewController.h"@interface leftViewController ()@end@implementation leftViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view.        //設定標題    self.title=@"left";    //設定背景色    self.view.backgroundColor=[UIColor redColor];    }- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}

 

 

  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.