【代码笔记】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来实现侧滑效果,可以说是效果很不错,自 ...
随机推荐
- JAVA - 优雅的记录日志(log4j实战篇)
写在前面 项目开发中,记录错误日志有以下好处: 方便调试 便于发现系统运行过程中的错误 存储业务数据,便于后期分析 在java中,记录日志有很多种方式: 自己实现 自己写类,将日志数据,以io操作方式 ...
- 自己对Debug的一些感悟
A.13-03-06记. 1.当项目中发现bug的时候,首先考虑如何重现,能够重现的bug比较好找寻根源. 2.思考下以前是否发现过类似bug,是否由一些外部配置所决定. 3.有循环时候注意临界条件.
- 字典树(Trie树)
1. trie基础 (1) 是什么? Trie,又称单词查找树或键树,是一种树形结构,是一种哈希树的变种. (2) 性质 根节点不包含字符,除根节点外每一个节点都只包含一个字符 从根节点到某一节点,路 ...
- 使用泛型元组替代out与ref形式传参
我们在开发的时候,都会常常遇到一个问题,如何为逻辑上返回多个对象设计方法签名.通常我们会想到使用out或ref修饰参数,或者麻烦些自己设定一个类型内部包含多个Object类型属性来接收多个返回值.这两 ...
- 【Java每日一题】20161018
20161017问题解析请点击今日问题下方的"[Java每日一题]20161018"查看 package Oct2016; public class Ques1018 { publ ...
- 修正 ListView 搜寻问题
问题:如果 SearchEdit 里已输入过搜寻字,再新建 ListView 项目后,会无法显示. 适用:Delphi XE5 源码下载:[原创]修正ListView搜寻问题.zip procedur ...
- springmvc(3)拦截器HandlerInterceptor源码的简单解析
其实拦截器就是我们的AOP编程.拦截器在我们的实际项目中实用性比较大的,比如:日志记录,权限过滤,身份验证,性能监控等等.下面就简单的来研究一下拦截器: public interface Handle ...
- LR常见问题整理
1.LoadRunner录制脚本时为什么不弹出IE浏览器? 当一台主机上安装多个浏览器时,LoadRunner录制脚本经常遇到不能打开浏览器的情况,可以用下面的方法来解决. LR11 无法弹出ie浏览 ...
- Windows 7 性能优化
1."计算机" 2.右键>"属性" 3."高级系统设置">"高级" 4."性能"> ...
- JavaScript学习(2):对象、集合以及错误处理
在这篇文章里,我们讨论一下JavaScript中的对象.数组以及错误处理. 1. 对象 对象是JavaScript中的一种基本类型,它内部包含一些属性,我们可以对这些属性进行增删操作. 1.1 属性 ...