手势

作者: 飞翔的鸵鸟 | 来源:发表于2016-02-23 10:43 被阅读68次

UIGestureRecognizer 手势识别器    抽象类

手势: 有规律的触摸

七种手势:  轻拍(tap) 长按(longPress) 旋转(rotation)

捏合(pinch)  拖拽(pan) 轻扫(swipe)

屏幕边缘拖拽(screenEdgePan)

1.先创建一个图片,在图片上实现手势功能

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 375, 667)];

imageView.center = self.view.center;

imageView.image = [UIImage imageNamed:@"h5.jpeg"];

[self.view addSubview:imageView];

[imageView release];

// 打开用户交互

imageView.userInteractionEnabled = YES;

2.轻拍tap

获取到轻拍手势时 让self调用tapAction:方法

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];

// 添加手势

[imageView addGestureRecognizer:tap];

// 内存管理

[tap release];

//点击次数

tap.numberOfTapsRequired = 2;

// 手指个数

tap.numberOfTouchesRequired = 2;

- (void)tapAction:(UITapGestureRecognizer *)tap

{

NSLog(@"轻拍");

}

3.长按longPress

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)];

[imageView addGestureRecognizer:longPress];

[longPress release];

// 长按时间

longPress.minimumPressDuration = 1;

- (void)longPressAction:(UILongPressGestureRecognizer *)longPress

{

// 长按手势是很多手势的基础

// 通过状态区分

if (longPress.state == UIGestureRecognizerStateBegan) {

NSLog(@"长按");

}

}

4.旋转rotation

UIRotationGestureRecognizer *rotain = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];

[imageView addGestureRecognizer:rotain];

[rotain release];

- (void)rotationAction:(UIRotationGestureRecognizer *)rotation

{

// UIView transform属性 专门用来进行形变(位置position/旋转rotation/缩放scale)设置

// 获取当前手势触发的视图

UIImageView *imgView = (UIImageView *)rotation.view;

// 设置transform变化旋转

imgView.transform = CGAffineTransformMakeRotation(rotation.rotation);

NSLog(@"旋转");

}

5.捏合pinch

UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchAction:)];

[imageView addGestureRecognizer:pinch];

[pinch release];

- (void)pinchAction:(UIPinchGestureRecognizer *)pinch{

// 获取view

UIImageView *imgView = (UIImageView *)pinch.view;

// 缩放scale(比例)

imgView.transform = CGAffineTransformScale(imgView.transform, pinch.scale, pinch.scale);

pinch.scale = 1;

NSLog(@"捏合");

}

相关文章

  • 手势

    点击手势 捏合手势 旋转手势 轻扫手势 拖拽手势 边缘平移手势 长按手势

  • iOS-手势详细参数说明

    敲击手势 长按手势 滑动手势 拖动手势 旋转手势 捏合手势 两种手势作用在同一个视图

  • 【iOS学习】——手势识别

    iOS 手势 手势需要开启用户交互 点击手势 单击手势 双击手势 添加 numberOfTapsRequired...

  • Swift - UIGestureRecognizer 各种手势

    1、点击手势2、拖动手势3、长按手势4、滑动手势5、捏合手势6、旋转手势 完整代码

  • iOS七种手势详解

    1、轻拍手势 2、捏合手势 3、旋转手势 4、平移手势 5、边缘轻扫手势 6、长按手势 7、轻扫手势 给image...

  • iOS手势总结

    1.轻拍手势 2.长按手势 3.轻扫手势 4.平移手势 5.捏合手势 6.旋转手势 7.边缘手势

  • iOS 手势

    修改时间: 2016-12-19修改次数: 0 手势传递 点击手势 捏合手势 轻扫手势 拖动手势 长按手势

  • iOS手势操作

    iOS手势有六种 手势类型: 手势状态: 创建View添加手势 1.轻点手势( UITapGestureRecog...

  • Vue手势

    点击手势 滑动手势 手势的方法

  • UI梳理——手势

    手势分类: 手势的创建: 方法的实现: 轻扫手势:UISwipeGestureRecognizer 长按手势: 以...

网友评论

      本文标题:手势

      本文链接:https://www.haomeiwen.com/subject/ugmbkttx.html