侧滑的简单实现
2016-01-08 00:00
99 查看
摘要: 侧滑其实挺长用的,这个很简单希望大神勿喷,这篇博文给广大小白提供一个简单的思路,大家可以试试#import "ViewController.h"#define OfSetX 100#define Width self.view.bounds.size.width@interface ViewController ()@property (strong, nonatomic) IBOutlet UIView *slideView;//从sb拖出来的最外层view@property (nonatomic,assign)float lastX;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.//给最外层view增加手势UIPanGestureRecognizer * panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(slide:)];[self.slideView addGestureRecognizer:panGestureRecognizer];}-(void)slide:(UIPanGestureRecognizer *)sender{CGRect frame = sender.view.frame;//以下代码就是判断偏移量做相应操作,如果想用Tableview做底层的话,换成TableViewController即可if (sender.state == UIGestureRecognizerStateBegan) {self.lastX = frame.origin.x;}CGPoint point =[sender translationInView:sender.view];NSLog(@"%@",NSStringFromCGPoint(point));frame.origin.x = point.x + self.lastX;sender.view.frame = frame;if (sender.state == UIGestureRecognizerStateEnded) {if (point.x < 100) {frame.origin.x = 0;}else{frame.origin.x = Width - OfSetX;}[UIView animateWithDuration:0.5 animations:^{sender.view.frame = frame;}];}}
相关文章推荐
- 使用VIPER构建iOS应用
- oracle跟踪事件(dump)总结
- UIScrollView的常用属性
- WebView添加进度条
- ABBYY FineReader 12对学生的重要作用
- ABBYY FineReader 12对学生的重要作用
- 怎么实现iMindMap中流程图的创建
- C语言编译全过程(有图有真相)
- 分享倒计时小工具(两个)
- 分享倒计时小工具(两个)
- 网页无刷新下载文件
- java设计模式——单例模式
- libubox
- 文档管理软件与OA办公系统的区别
- Head First Java 阅读笔记
- Dell R720 Server 2008 R2 安装 AMD firepro V4900 显卡
- Dell R720 4块硬盘,两块做普通盘,两块做Raid0 安装
- https://raw.githubusercontent.com/racaljk/hosts/ma
- 深圳泊众棋牌 精品化游戏标杆
- java文件cmd窗口编译后,运行class文件时报找不到类的错误。