IOS开发—7种常用手势UIGestureRecognizer介绍
来源:互联网 发布:php未来10年发展 编辑:程序博客网 时间:2024/05/22 15:30
7种常用手势UIGestureRecognizer介绍
- #import "ViewController.h"
- @interface ViewController ()
- {
- UITapGestureRecognizer *_tap;
- UIPanGestureRecognizer *_pan;
- UIPinchGestureRecognizer *_pinch;
- UIRotationGestureRecognizer *_rotation;
- UISwipeGestureRecognizer *_swipe;
- UILongPressGestureRecognizer *_longpress;
- UIScreenEdgePanGestureRecognizer *_edgePan;
- }
- @property (nonatomic, weak) IBOutlet UIView *testView;
- @end
- @implementation ViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self addTapGesture];
- [self addPanGesture];
- [self addPinchGesture];
- [self addRotationGesture];
- [self addSwipeGesture];
- [self addLongpressGesture];
- [self addEdgePanGesture];
- // 手势谦让
- [self gestureHumility];
- }
- #pragma mark - 手势
- //单击
- - (void)addTapGesture{
- _tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
- _tap.numberOfTapsRequired = 1;
- [_testView addGestureRecognizer:_tap];
- }
- //拖拽
- - (void)addPanGesture{
- _pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
- _pan.minimumNumberOfTouches = 1;
- [_testView addGestureRecognizer:_pan];
- }
- //捏合
- - (void)addPinchGesture{
- _pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
- [_testView addGestureRecognizer:_pinch];
- }
- //旋转
- - (void)addRotationGesture{
- _rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
- [_testView addGestureRecognizer:_rotation];
- }
- //轻扫
- - (void)addSwipeGesture{
- _swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
- //指定扫动方向
- _swipe.direction = UISwipeGestureRecognizerDirectionDown;
- [_testView addGestureRecognizer:_swipe];
- }
- //长按
- - (void)addLongpressGesture{
- _longpress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longpressAction:)];
- _longpress.minimumPressDuration = 1.0;
- [_testView addGestureRecognizer:_longpress];
- }
- //边缘滑动手势
- - (void)addEdgePanGesture{
- _edgePan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(edgePanAction:)];
- _edgePan.edges = UIRectEdgeLeft;
- [self.view addGestureRecognizer:_edgePan];
- }
- #pragma mark - 动作
- //单击
- - (void)tapAction:(UITapGestureRecognizer *)tap{
- NSLog(@"单击");
- }
- //拖拽
- - (void)panAction:(UIPanGestureRecognizer *)pan{
- NSLog(@"拖拽");
- CGPoint point = [pan translationInView:pan.view];
- // pan.view.transform =CGAffineTransformMakeTranslation(point.x, point.y);
- pan.view.transform = CGAffineTransformTranslate(pan.view.transform, point.x, point.y);
- [pan setTranslation:CGPointZero inView:pan.view];
- }
- //捏合
- - (void)pinchAction:(UIPinchGestureRecognizer *)pinch{
- NSLog(@"捏合");
- pinch.view.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
- }
- //旋转
- - (void)rotationAction:(UIRotationGestureRecognizer *)rotation{
- NSLog(@"旋转");
- rotation.view.transform = CGAffineTransformMakeRotation(rotation.rotation);
- }
- //轻扫
- - (void)swipeAction:(UISwipeGestureRecognizer *)swipe{
- NSLog(@"向下轻扫");
- }
- //长按
- - (void)longpressAction:(UILongPressGestureRecognizer *)longpress{
- NSLog(@"长按");
- }
- //边缘滑动手势
- - (void)edgePanAction:(UIScreenEdgePanGestureRecognizer *)edgePan{
- NSLog(@"左边缘滑动");
- UIColor *random = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0];
- self.view.backgroundColor = random;
- }
- #pragma mark - privatemethods
- - (void)gestureHumility{
- [_pan requireGestureRecognizerToFail:_swipe];
- }
- @end
0 0
- IOS开发—7种常用手势UIGestureRecognizer介绍
- IOS开发—7种常用手势UIGestureRecognizer介绍
- [转]7种常用手势UIGestureRecognizer介绍
- IOS开发之手势——UIGestureRecognizer
- IOS开发之手势——UIGestureRecognizer
- IOS开发之手势—UIGestureRecognizer 共存
- IOS开发之手势——UIGestureRecognizer 手势共存
- IOS开发手势-----UIGestureRecognizer 共存
- IOS开发之手势(UIGestureRecognizer)
- IOS开发之手势UIGestureRecognizer
- iOS开发之手势(UIGestureRecognizer)
- IOS开发之手势UIGestureRecognizer
- iOS开发 - 手势识别(UIGestureRecognizer)
- iOS开发 手势识别UIGestureRecognizer
- 【iOS】六种手势UIGestureRecognizer
- iOS UIGestureRecognizer (手势的基本知识介绍)
- iOS UIGestureRecognizer (手势的基本知识介绍)
- iOS开发:如何使用iOS手势UIGestureRecognizer
- android lcd帧率
- GRE填空对比词汇——稳定VS变化
- iOS每日一记 ------之正则表达式 判断手机号 限制textfiled的长度
- 解决maven项目在eclipse中debug时看不到源码
- xcode 配置SVN详细步骤
- IOS开发—7种常用手势UIGestureRecognizer介绍
- duilib按钮的右击事件
- debian下安装jdk
- C/C++程序从编译到最终生成可执行文件的过程分析
- J2EE是什么(一)
- 百度地图API显示多个标注点带提示的代码
- 集合操作的ConcurrentModificationException
- webstorm 使用
- 【Java安全技术探索之路系列:Java可扩展安全架构】之四:JCA(三):JCA编程模型