使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏

A UIScreenEdgePanGestureRecognizer looks for panning (dragging) gestures that start near an edge of the screen. The system uses screen edge gestures in some cases to initiate view controller transitions. You can use this class to replicate the same gesture behavior for your own actions.

UIScreenEdgePanGestureRecognizer看起来像pan手势,它是检测屏幕边缘的pan手势的。系统在某些controller转场的时候会使用这个手势。你也可以使用这个手势做其他的事情。

源码:

#import "RootViewController.h"

@interface RootViewController ()<UIGestureRecognizerDelegate>

{

    CGFloat  _centerX;
CGFloat _centerY;
UIView *_backgroundView; } @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad]; // 存储坐标
_centerX = self.view.bounds.size.width / ;
_centerY = self.view.bounds.size.height / ;
self.view.backgroundColor = [UIColor blackColor]; // 屏幕边缘pan手势(优先级高于其他手势)
UIScreenEdgePanGestureRecognizer *leftEdgeGesture = \
[[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self
action:@selector(handleLeftEdgeGesture:)];
leftEdgeGesture.edges = UIRectEdgeLeft; // 屏幕左侧边缘响应
[self.view addGestureRecognizer:leftEdgeGesture]; // 给self.view添加上 // 设置一个UIView用来替换self.view,self.view用来当做背景使用
_backgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
_backgroundView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:_backgroundView]; // 展示的view
UIView *showView_01 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
showView_01.tag = 0x1;
showView_01.backgroundColor = [UIColor redColor];
[_backgroundView addSubview:showView_01];
} - (void)handleLeftEdgeGesture:(UIScreenEdgePanGestureRecognizer *)gesture
{
// 获取到当前被触摸的view
UIView *view = [self.view hitTest:[gesture locationInView:gesture.view]
withEvent:nil]; NSLog(@"tag = %ld", (long)view.tag); if(UIGestureRecognizerStateBegan == gesture.state ||
UIGestureRecognizerStateChanged == gesture.state)
{
// 根据被触摸手势的view计算得出坐标值
CGPoint translation = [gesture translationInView:gesture.view];
NSLog(@"%@", NSStringFromCGPoint(translation)); NSLog(@"进行中"); // 进行设置
_backgroundView.center = CGPointMake(_centerX + translation.x, _centerY);
}
else
{
// 恢复设置
[UIView animateWithDuration:. animations:^{
_backgroundView.center = CGPointMake(_centerX, _centerY); }];
}
} @end

RootViewController.m

处理手势:

效果如下图:

如果想与其他手势并发操作,实现如下代理即可:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏的更多相关文章

  1. 使用TFHpple解析html

    使用TFHpple解析html https://github.com/topfunky/hpple 前期准备工作 引入静态库文件 添加库文件的 header search paths(注意,必须选中 ...

  2. iOS html格式解析

    使用TFHpple解析html https://github.com/topfunky/hpple 前期准备工作 引入静态库文件 添加库文件的 header search paths(注意,必须选中 ...

  3. 使用Ant Design写一个仿微软ToDo

    实习期的第一份活,自己看Ant Design的官网学习,然后用Ant Design写一个仿微软ToDo. 不做教学目的,只是记录一下. 1.学习 Ant Design 是个组件库,想要会用,至少要知道 ...

  4. 史上最全的常用iOS的第三方框架

    文章来源:http://blog.csdn.net/sky_2016/article/details/45502921 图像: 1.图片浏览控件MWPhotoBrowser       实现了一个照片 ...

  5. 常用iOS的第三方框架

    图像:1.图片浏览控件MWPhotoBrowser       实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等 ...

  6. iOS:抽屉侧滑动画两种形式(1、UIView侧滑 2、ViewController侧滑)

    前言: 在iOS中抽屉动画是很常用的一种技术,使用它有很炫的体验效果,为app增添特色,形式就两种,一个是UIView的侧滑,另一个就是ViewController的侧滑. 实现方式: 抽屉侧滑动画有 ...

  7. 一些Demo链接

    youtube下载神器:https://github.com/rg3/youtube-dl我擦咧vim插件:https://github.com/Valloric/YouCompleteMevim插件 ...

  8. iOS 中有用的开源库

    youtube下载神器:https://github.com/rg3/youtube-dl vim插件:https://github.com/Valloric/YouCompleteMe vim插件配 ...

  9. ios的一些开源资源

    1. http://www.open-open.com/lib/view/open1428646127375.html vim插件:https://github.com/Valloric/YouCom ...

随机推荐

  1. ImportError: libSM.so.6: cannot open shared object file: No such file or directory

    Solution sudo apt-get install libsm6 Similarly ImportError: libXrender.so.1: cannot open shared obje ...

  2. linux下执行Python项目,crontab不能定时执行任务

    问题描述: 在项目下的文件执行脚本,可以手动执行 在其他文件目录下,手动执行脚本报错误,提示不存在该模块. 解决方法: 文件头加上: import sysimport ossys.path += [ ...

  3. 使用jquery处理数据时要注意的问题

    现在的网站越来越重视用户体验,网站必须即时反应,前端技术越来越重要了,以前我们都用javascript,后来出现了很多js的框架,调用起来也很方便,但是随着网页上加载的数据越来越多,使用jquery的 ...

  4. C语言入门语法

    一.数据类型 常量 1.通过预处理声明常量 #include <stdio.h> #define PRICE 100 int main() { printf("价格:%d\n&q ...

  5. YII框架路由配置

    首先要在服务器配置(httpd.conf)中开启重写模块: #开启重写模块,将其前面的#去掉 LoadModule rewrite_module modules/mod_rewrite.so #Dir ...

  6. ASP.NET MVC4 新手入门教程之五 ---5.用控制器访问模型数据

    在本节中,将创建一个新的MoviesController类并编写代码来检索电影数据并将其显示在浏览器中使用一个视图模板. 才走出下一步生成应用程序. 用鼠标右键单击控制器文件夹中并创建一个新的 Mov ...

  7. 缓存框架EhCache的简单使用

    缓存框架EhCache的简单使用: 1.Spring和EhCache框架整合 1.1导入jar包 <dependencies> <dependency> <groupId ...

  8. Discuz x3 UCenter实现同步登陆原理

    1.Discuz x3 的登录页面URL是:/member.php?mod=logging&action=login 2.这个登录页面,登录提交的地址是: <form method=&q ...

  9. 缓存与DB数据一致性问题解决的几个思路

    使用缓存必然会碰到缓存跟真实数据不一致的问题,虽然我们会在数据发生变化时通知缓存,但是这个延迟时间内必然会导致数据不一致,如何解决一般有下面几个思路: 首先,当这个延迟如果在业务上时可以接受的,比如文 ...

  10. jquery+springMVC实现文件上传

    此文章是基于 搭建Jquery+SpringMVC+Spring+Hibernate+MySQL平台 一. jar包介绍 1. commons-fileupload-1.3.1.jar 二. 相关程序 ...