说明:以下方法是开发中使用的方法,有什么不对的或者好的方法,请多多指教!

此处的边缘手势是用来控制左侧抽屉视图的弹出以及收回。

添加手势 :

  1. 页面上有多个手势时需要遵循 UIGestureRecognizerDelegate 协议
 @interface HomePageViewController ()<LeftDrawerViewDelegate,UITableViewDataSource,UITableViewDelegate,SDCycleScrollViewDelegate,UIGestureRecognizerDelegate>{

     LeftDrawerViewViewController *_leftDrawerVC;

     UITableView *_tableView;

     UIView *_headeView;

     //轮播图详情展示URL数组
NSMutableArray *_urlArr; BOOL _leftDrawerState; UIView *_maskView; }

2.添加边缘手势

  //添加边缘手势
UIScreenEdgePanGestureRecognizer *screenEdgeGesOut = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenGesOut:)];
screenEdgeGesOut.edges = UIRectEdgeLeft; [self.view addGestureRecognizer:screenEdgeGesOut]; UIScreenEdgePanGestureRecognizer *screenEdgeGesIn = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenGesIn:)];
screenEdgeGesIn.edges = UIRectEdgeRight; [self.view addGestureRecognizer:screenEdgeGesIn];

3.实现手势中的方法以及协议中的方法

//控制抽屉视图弹出
- (void)screenGesOut:(UIScreenEdgePanGestureRecognizer *)ges{ UIView *tempUV = [self.view.window viewWithTag:DRAWERTAG]; if (_leftDrawerState == NO) { _leftDrawerState = YES; _maskView = [[UIView alloc]initWithFrame:self.view.frame];
[self.view addSubview:_maskView];
_maskView.backgroundColor = [UIColor lightGrayColor];
_maskView.alpha = 0.3; [UIView animateWithDuration:0.3 animations:^{ CGPoint ptDrawer = tempUV.center; ptDrawer.x += kSCREENWIDTH */;
tempUV.center = ptDrawer; // tabbarcontroller视图动
CGPoint ptTabbar = self.tabBarController.view.center;
ptTabbar.x += kSCREENWIDTH */;
self.tabBarController.view.center = ptTabbar; }]; }
}
//控制抽屉视图收回
- (void)screenGesIn:(UIScreenEdgePanGestureRecognizer *)ges{
UIView *tempUV = [self.view.window viewWithTag:DRAWERTAG]; if(_leftDrawerState == YES){ _leftDrawerState = NO; [_maskView removeFromSuperview]; [UIView animateWithDuration:0.3 animations:^{ CGPoint ptDrawer = tempUV.center;
ptDrawer.x -= kSCREENWIDTH */;
tempUV.center = ptDrawer; // tabbarcontroller视图动
CGPoint ptTabbar = self.tabBarController.view.center;
ptTabbar.x -= kSCREENWIDTH */;
self.tabBarController.view.center = ptTabbar;
}];
}
} //页面有多个手势时 需要遵循协议-> UIGestureRecognizerDelegate 以及实现协议中的方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ return YES;
}

iOS开发中常用的手势---边缘手势的更多相关文章

  1. iOS开发中常用的数学函数

    iOS开发中常用的数学函数 /*---- 常用数学公式 ----*/ //指数运算 3^2 3^3 NSLog(,)); //result 9 NSLog(,)); //result 27 //开平方 ...

  2. iOS开发中常用的分类方法---UIImage+Category

    在开发中使用分类对原有的系统类进行方法扩展,是增强系统原有类功能的常见做法. /** * 自由拉伸一张图片 * * @param name 图片名字 * @param left 左边开始位置比例 值范 ...

  3. iOS开发中 常用枚举和常用的一些运算符(易错总结)

    1.色值的随机值: #define kColorValue arc4random_uniform(256)/255.0 // arc4random_uniform(256)/255.0; 求出0.0~ ...

  4. ios开发中常用的也是最基本的mysql语句

    MySQL常用基本SQL语句小结——(转) sql语言不经常用,每次再用都隔好久的时间,以致最基本的都想不起来了,只好转一篇记着= - 找的时候方便 SQL分类:  DDL—数据定义语言(CREATE ...

  5. iOS开发中常用的设计模式

    常用的设计模式(一)代理模式应用场景:当一个类的某些功能需要由别的类来实现,但是又不确定具体会是哪个类实现.优势:解耦合敏捷原则:开放-封闭原则实例:tableview的 数据源delegate,通过 ...

  6. iOS开发中常用的单例

    定义:一个类的对象,无论在何时创建.无论创建多少次,创建出来的对象都是同一个对象. 使用场景:当有一些数据需要共享给别的类的时候,就可以把这些数据保存在单例对象中.   关键代码: + (instan ...

  7. iOS开发中常用的宏

    前言 今天将一些简化工程代码的宏定义拿出来分享一下,自定义一些宏可以有效的简化代码,提高编码效率. Application #define APPLICATION [UIApplication sha ...

  8. iOS开发中常用第三方库的使用和配置-GDataXML

    这篇文章旨在给自己以后需要时能及时的查到,省得每次都去baidu. 1. xml解析库-GDataXML 参考文章:http://blog.csdn.net/tangren03/article/det ...

  9. 第三十篇、iOS开发中常用的宏

    //字符串是否为空 #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str leng ...

随机推荐

  1. POJ3984 迷宫问题

    典型BFS. #include <iostream> #include <memory.h> #include <queue> #include <map&g ...

  2. POJ_1182_食物链_[NOI]_(并查集)

    描述  http://poj.org/problem?id=1182 共A,B,C三种动物,A吃B,B吃C,C吃A.给出询问 q : t , x , y , 表示: x 与 y 是同类 ( t==1 ...

  3. DevExpress中XtraGrid控件对GridView每行的颜色设置 zt

    改变行颜色 private void GridView1_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArg ...

  4. Tag file directory /struts-tags does not start with "/WEB-INF/tags"

    使用自定义标签,记得引用路径 <%@taglib prefix="s" uri="/struts-tags" %>

  5. JavaScript高级程序设计32.pdf

    样式 在HTML中定义样式的方式有3种:通过<link/>元素包含外部样式表文件.使用<style/>元素定义嵌入式样式,以及使用style特性定义针对特定元素的样式,“DOM ...

  6. Bzoj 2243: [SDOI2011]染色 树链剖分,LCT,动态树

    2243: [SDOI2011]染色 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 5020  Solved: 1872[Submit][Status ...

  7. Opencl API解释(一)

    首先注明:我用的AMD的opencl,它有很多sample代码,结合代码来解释这些API Opencl 常用的API 汇总总结: 信息查询函数 1. cl_int clGetDeviceInfo(cl ...

  8. forward和redirect 的区别

    一.使用区别 1.从地址栏显示来说 forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,然后把这些内容再发给浏览器.浏览器根本不知道服务器发送的内容从哪里来 ...

  9. [置顶] 深入理解android之IPC机制与Binder框架

    [android之IPC机制与Binder框架] [Binder框架.Parcel.Proxy-Stub以及AIDL] Abstract [每个平台都会有自己一套跨进程的IPC机制,让不同进程里的两个 ...

  10. zoj3329 One Person Game

    One Person Game Time Limit: 1 Second Memory Limit: 32768 KB Special Judge There is a very simple and ...