IOS 手势之左右滑动UISwipeGestureRecognizer
来源:互联网 发布:小程序源码上传服务器 编辑:程序博客网 时间:2024/06/10 02:36
做个左右滑动手势.
1. 在"ViewController.h"中增加两个手势property.
@property (nonatomic, strong) UISwipeGestureRecognizer *leftSwipeGestureRecognizer;
@property (nonatomic, strong) UISwipeGestureRecognizer *rightSwipeGestureRecognizer;
并synthesize到"ViewController.m"文件中.
2.在"ViewController.m"文件中的"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.并在"ViewController.m"中增加如下方法;
- (void)handleSwipes:(UISwipeGestureRecognizer *)sender
{
if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
CGPoint labelPosition = CGPointMake(self.swipeLabel.frame.origin.x - 100.0, self.swipeLabel.frame.origin.y);
self.swipeLabel.frame = CGRectMake( labelPosition.x , labelPosition.y , self.swipeLabel.frame.size.width, self.swipeLabel.frame.size.height);
self.swipeLabel.text = @"尼玛的, 你在往左边跑啊....";
}
if (sender.direction == UISwipeGestureRecognizerDirectionRight) {
CGPoint labelPosition = CGPointMake(self.swipeLabel.frame.origin.x + 100.0, self.swipeLabel.frame.origin.y);
self.swipeLabel.frame = CGRectMake( labelPosition.x , labelPosition.y , self.swipeLabel.frame.size.width, self.swipeLabel.frame.size.height);
self.swipeLabel.text = @"尼玛的, 你在往右边跑啊....";
}
}
4. 保存, 编译, 运行....
- IOS 手势之左右滑动UISwipeGestureRecognizer
- iOS 手势之左右滑动UISwipeGestureRecognizer
- IOS 手势之左右滑动
- ios UISwipeGestureRecognizer 左右滑动隐藏按钮
- ios 左右滑动手势
- UISwipeGestureRecognizer滑动手势
- ios开发之UISwipeGestureRecognizer手势识别
- ios学习之UISwipeGestureRecognizer手势识别
- iOS手势之UISwipeGestureRecognizer的正确用法
- swiftUI基础 滑动手势UISwipeGestureRecognizer
- 20. 手势识别之UISwipeGestureRecognizer
- UISwipeGestureRecognizer 滑动手势方向的判定
- android 手势左右滑动
- android手势左右滑动
- android 手势左右滑动
- android 手势左右滑动
- android手势左右滑动
- iOS手势之 响应上下左右滑动手势
- iOS中的文件I/O
- Android IPC方式
- sun关于tmp文件的描述
- 位图法排序
- c++运算符重载
- IOS 手势之左右滑动UISwipeGestureRecognizer
- GHOST 博客安装中文全攻略
- Solr初级教程
- 15泛型_15.1与C++比较
- Java的接口问题
- DWZ学习总结《一》
- Android studio修改变更Eclipse快捷键
- Using Process Memory Matrix script for understanding Oracle process memory usage
- Valid Palindrome