【代码笔记】iOS-侧滑效果
一,效果图。

二,工程图。

三,代码。
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.
}

【代码笔记】iOS-侧滑效果的更多相关文章
- iOS 下如果存在UIScrollerView 使用UIScreenEdgePanGestureRecognizer实现侧滑效果失效的问题
当你在使用UIScreenEdgePanGestureRecognizer手势实现侧滑的时候,如果后期你导航控制器push出的界面中包含UIScrollerView,这个时候你会发现,侧滑效果无法实现 ...
- 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程
一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...
- 【转】提示框第三方库之MBProgressHUD iOS toast效果 动态提示框效果
原文网址:http://www.zhimengzhe.com/IOSkaifa/37910.html MBProgressHUD是一个开源项目,实现了很多种样式的提示框,使用上简单.方便,并且可以对显 ...
- 笔记-iOS 视图控制器转场详解(上)
这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...
- Android仿IOS回弹效果 ScrollView回弹 总结
Android仿IOS回弹效果 ScrollView回弹 总结 应项目中的需求 须要仿IOS 下拉回弹的效果 , 我在网上搜了非常多 大多数都是拿scrollview 改吧改吧 试了一些 发现总 ...
- IOS开发笔记 IOS如何访问通讯录
IOS开发笔记 IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...
- Android 实现高仿iOS桌面效果之可拖动的GridView(上)
转载请标明出处:http://blog.csdn.net/sk719887916/article/details/40074663,作者:skay 最近项目中遇到一个LIstview的拖动效 ...
- 自定义控件?试试300行代码实现QQ侧滑菜单
Android自定义控件并没有什么捷径可走,需要不断得模仿练习才能出师.这其中进行模仿练习的demo的选择是至关重要的,最优选择莫过于官方的控件了,但是官方控件动辄就是几千行代码往往可能容易让人望而却 ...
- 搜索菜单栏侧滑效果控件SearchView
搜索菜单栏侧滑效果控件SearchView 本人视频教程系类 iOS中CALayer的使用 效果1: 效果2: 项目中用到的图片 bgImg@2x.png: 源码: SearchView.h + ...
- Android使用DrawerLayout仿qq6.6版本侧滑效果
一讲到侧滑菜单,我相信大家都会想到一个开源控件SlidingMenu,在google还没有出来DrawerLayout的时候几乎都是使用Slidingmenu来实现侧滑效果,可以说是效果很不错,自 ...
随机推荐
- Auto Mapper01
在项目中一直在使用Auto Mapper技术,但是只是会简单的使用,对其里面的一些具体的细节和知识点不是很清楚,现在就跟着我从最基础的知识点来重新认识下,AutoMapper技术吧. ...
- vue之watch用法
对应一个对象,键是观察表达式,值是对应回调.值也可以是方法名,或者是对象,包含选项.在实例化时为每个键调用 $watch() ; //使用官方vue-cli脚手架书写<template> ...
- 基于C#的MongoDB数据库开发应用(3)--MongoDB数据库的C#开发之异步接口
在前面的系列博客中,我曾经介绍过,MongoDB数据库的C#驱动已经全面支持异步的处理接口,并且接口的定义几乎是重写了.本篇主要介绍MongoDB数据库的C#驱动的最新接口使用,介绍基于新接口如何实现 ...
- .Net在线付款---Paypal在线付款开发过程
原文:.Net在线付款---Paypal在线付款开发过程 最近在做一个Web订单项目,项目有一个需求就是集成Paypal与Paydollar在线付款,一开始看到这个需求也是傻了眼,因为以前从来没有做过 ...
- EC笔记,第一部分:2.尽量以const,enum,inline代替#define
02.尽量以const,enum,inline代替#define 原因:编译前的预处理会替换宏,所以调试的时候找不到错误 1.const 尽量用const替代常量宏定义 两种特殊情况: (1).常量指 ...
- SSH实例(7)
运行结果. 浏览课程: 添加课程: 还有删除课程,这里就不演示了.
- 动态加载HTML后使用query修改标签样式
下面的IMG 标签的宽度从后台返回是10PX,加载完毕后,修改成100PX,注意:拼接的代码在 body标签之后,或则直接在HTML外面增加也可以 <html> <head> ...
- 操作系统笔记系列 一 Linux
学习资料: 1.http://www.icoolxue.com/ 马士兵 1.Linux 服务器端,目前98%的服务器都是Linux. 2.
- 初识 PHPunit stub 模拟返回数据
这是这段时间以来结合 PHPunit 文档和大牛们的讲解,想记录下自己学习到的知识,未来参考补充,完善学到的东西 我们一般使用单测对公司业务里的代码进行测试,他会帮忙找到你的一个个小小的思考不够全面的 ...
- c# 学习心得(函数方法类)
函数或者说方法都是写在类下的,我们可以通过函数名来调用它们.首先,我们要弄清楚为什么会有函数或者说方法这种东西?这里,我们使用了与前一篇同样的思维方式,先从它的目的或者实用价值出发.当我们在编写程序的 ...