这是一个很简单的实例,向做滑动,打开侧边栏,向右滑动,关闭侧边栏。

1. 在ViewController中添加两个属性

@property (nonatomic, strong) UISwipeGestureRecognizer *leftSwipeGestureRecognizer;
@property (nonatomic, strong) UISwipeGestureRecognizer *rightSwipeGestureRecognizer;

2. 在ViewDidLoad中添加以下代码,创建左右两个方向的手势识别器,并设置处理方法

self.leftSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];self.rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipes:)];self.leftSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;self.rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;[self.view addGestureRecognizer:self.leftSwipeGestureRecognizer];[self.view addGestureRecognizer:self.rightSwipeGestureRecognizer];

3. 实现处理方法,向左滑动时,打开侧边栏,向右滑动时,关闭侧边栏

- (void)handleSwipes:(UISwipeGestureRecognizer *)sender
{if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {[sideBar showMenu];}if (sender.direction == UISwipeGestureRecognizerDirectionRight) {[sideBar dismissMenu];}
}

ios 左右滑动手势相关推荐

  1. ios 禁用滑动手势_如何禁用笔记本电脑上的Windows 8滑动手势?

    ios 禁用滑动手势 If you're not a fan of the touchpad-based swipe gestures in Windows 8 there is a way to c ...

  2. iOS开发-UISwipeGestureRecognizer滑动手势

    滑动手势也算是iOS中交互中很重要的一部分,上下左右滑动,UISwipeGestureRecognizer可以很轻松的解决这个问题,没什么难度直接看代码吧: UISwipeGestureRecogni ...

  3. ios开发学习-手势交互(Gesture)效果源码分享

    qianqianlianmeng ios开发学习-手势交互(Gesture)效果源码分享 All Around Pull View 介绍:实现视图四个方向(上下左右)都能够拖动更新(pull to r ...

  4. ios 轻扫手势_轻扫即可快速删除iOS计算器中的数字

    ios 轻扫手势 iOS' built-in calculator is a basic, simple-to-use calculator that's very handy for doing s ...

  5. IOS开发之手势——UIGestureRecognizer 共存

    IOS开发之手势--UIGestureRecognizer 共存 在 iPhone 或 iPad 的开发中,除了用 touchesBegan / touchesMoved / touchesEnded ...

  6. [iOS]调和 pop 手势导致 AVPlayer 播放卡顿

    作者 NewPan 关注 2017.07.15 14:24* 字数 3110 阅读 749评论 8喜欢 17 声明:我为这个框架写了四篇文章: 第一篇:[iOS]UINavigationControl ...

  7. bootstrap轮播如何支持移动端滑动手势

    1.下载滑动手势 js 插件:hammer.js //cdn.bootcss.com/hammer.js/2.0.8/hammer.min.js 2.写一个javascript命令调用hammer.j ...

  8. 解决页面使用overflow: scroll在iOS上滑动卡顿的问题

    解决页面使用overflow: scroll在iOS上滑动卡顿的问题 参考文章: (1)解决页面使用overflow: scroll在iOS上滑动卡顿的问题 (2)https://www.cnblog ...

  9. 小程序禁用ios 左右滑动_如何在使用应用程序时禁用iOS控制中心

    小程序禁用ios 左右滑动 The Control Center has proven to be a thoughtful and welcome addition to iOS, but it c ...

最新文章

  1. 1_MVC+EF+Autofac(dbfirst)轻型项目框架_core层(以登陆为例)
  2. Android studio之NDK integration is deprecated in the current plugin解决办法
  3. 确定S中最接近中位数的k个元素(算法导论第三版9.3-7)
  4. 计算机网络考试成绩分析报告,成绩分析报告范文_成绩分析总结与反思
  5. 理论物理极础11:电力和磁力
  6. redis 配置文件配置
  7. 不到30行JS代码实现的Excel表格
  8. excel导出文本格式设置为数值(easypoi)
  9. java怎么实现微博评论_用户操作之回复评论、查看微博评论功能实现一
  10. 网络 打印机怎么连接?
  11. 根据3倍图生成2倍图和1倍图
  12. HDU 1429 bfs 状态压缩
  13. 腾讯2016实习生招聘有感
  14. Oracle 11g 修改表的所属表空间
  15. mysql的pv跟pc_PC板PV板PVC板PPV板区别与用途
  16. VMWare连接外网的配置操作
  17. CentOS8—ssh免密登录
  18. 链路追踪工具 skywalking
  19. 无模型预测控制(model-free predictive control)+ESO
  20. 哈密顿算子及拉普拉斯算子的基本性质及证明

热门文章

  1. 集合长度可变的实现原理(解析为什么集合长度可变)
  2. 老七苏-37:明日之星 苏-37是在苏-35的基础上改进而成的。
  3. 开启微信悬浮窗权限有什么用_新版微信功能!微信也可以设置主题皮肤了,不再是单调的白色,这也太好看了吧!...
  4. VLAN端口类型(access、Trunk、Hybrid)
  5. 如何在jupyter notebook 中修改主题、字体、字号等
  6. Manjaro更换系统默认字体,主题
  7. 互联网大厂面试必问的JVM底层原理,美团阿里Java程序员晒工资被围观
  8. 两天赚 2 千,用 Python 接私活,真香!
  9. 【Excel】之数据透视表及动态图表
  10. React最佳实践系列 —— Dva快速入门