使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏
使用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侧边栏的更多相关文章
- 使用TFHpple解析html
使用TFHpple解析html https://github.com/topfunky/hpple 前期准备工作 引入静态库文件 添加库文件的 header search paths(注意,必须选中 ...
- iOS html格式解析
使用TFHpple解析html https://github.com/topfunky/hpple 前期准备工作 引入静态库文件 添加库文件的 header search paths(注意,必须选中 ...
- 使用Ant Design写一个仿微软ToDo
实习期的第一份活,自己看Ant Design的官网学习,然后用Ant Design写一个仿微软ToDo. 不做教学目的,只是记录一下. 1.学习 Ant Design 是个组件库,想要会用,至少要知道 ...
- 史上最全的常用iOS的第三方框架
文章来源:http://blog.csdn.net/sky_2016/article/details/45502921 图像: 1.图片浏览控件MWPhotoBrowser 实现了一个照片 ...
- 常用iOS的第三方框架
图像:1.图片浏览控件MWPhotoBrowser 实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等 ...
- iOS:抽屉侧滑动画两种形式(1、UIView侧滑 2、ViewController侧滑)
前言: 在iOS中抽屉动画是很常用的一种技术,使用它有很炫的体验效果,为app增添特色,形式就两种,一个是UIView的侧滑,另一个就是ViewController的侧滑. 实现方式: 抽屉侧滑动画有 ...
- 一些Demo链接
youtube下载神器:https://github.com/rg3/youtube-dl我擦咧vim插件:https://github.com/Valloric/YouCompleteMevim插件 ...
- iOS 中有用的开源库
youtube下载神器:https://github.com/rg3/youtube-dl vim插件:https://github.com/Valloric/YouCompleteMe vim插件配 ...
- ios的一些开源资源
1. http://www.open-open.com/lib/view/open1428646127375.html vim插件:https://github.com/Valloric/YouCom ...
随机推荐
- 数据备份及恢复(mongodump/mongorestore)
说明 1.mongodump创建高保真的BSON文件,mongorestore可以用其恢复数据库.对于小型数据库的备份和恢复,这两个工具非常简单和高效,但对于大型数据库的备份并不理想.2.mongod ...
- CSAPP阅读笔记-存储器层次结构-第六章-P400-P462
6.1 存储技术 1.随机访问存储器(RAM),是易失性存储器,掉电存储信息会丢失,与之相对的是非易失性存储器(ROM),它掉电后存储信息不丢失,但前者访问速度较快,但容量有限,通常只有几百或几千兆字 ...
- ios UISearchDisplayController 实现 UITableView 搜索功能
UISearchDisplayController 是苹果专为 UITableView 搜索封装的一个类. 里面内置了一个 UITableView 用于显示搜索的结果.它可以和一个需要搜索功能的 co ...
- preg_match()——php
第一,让我们看看两个特别的字符:‘^’和‘$’他们是分别用来匹配字符串的开始和结束,以下分别举例说明: "^The": 匹配以 "The"开头的字符串; &qu ...
- step2: 爬取廖雪峰博客
#https://zhuanlan.zhihu.com/p/26342933 #https://zhuanlan.zhihu.com/p/26833760 scrapy startproject li ...
- mybatis mapper调用mysql存储过程
mybatis版本:3.4.4 存储过程 1.mapper.xml文件中配置相关的sql语句. <select id="callTest" statementType=&qu ...
- Expression Blend实例中文教程(4) - 布局控件快速入门Canvas
上一篇,我介绍了Silverlight控件被分为三种类型, 第一类: Layout Controls(布局控件) 第二类: Item Controls (项目控件) 第三类: User Interac ...
- Opencv中图像的遍历与像素操作
Opencv中图像的遍历与像素操作 OpenCV中表示图像的数据结构是cv::Mat,Mat对象本质上是一个由数值组成的矩阵.矩阵的每一个元素代表一个像素,对于灰度图像,像素是由8位无符号数来表示(0 ...
- 十、集成使用redis
一.简介 redis是一种非关系型数据库,它的数据结构是key-value的存储形式:能够支持多种类型的数据存储,如:string/list/map/object...等.springboot自然也对 ...
- Java 异常的处理方式--throws和try catch
异常的第一种处理方式throws. 看以下例子: import java.io.*;public class ExceptionTest04{ public static void main(Stri ...