美文网首页
UI手势识别器

UI手势识别器

作者: 焦六金Jxx | 来源:发表于2016-02-24 18:14 被阅读0次

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

self.view.backgroundColor = [UIColor whiteColor];

//UIGestureRecognizer 手势识别器

// 手势 :有规律的触摸

//  UIGestureRecognizer 抽象类

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

//捏合(pinch) 拖拽(pan) 轻扫(swipe) 屏幕边缘拖拽(screenEdgePan)

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];

imgView.center = self.view.center;

imgView.image = [UIImage imageNamed:@"spurs.jpg"];

[self.view addSubview:imgView];

[imgView release];

//打开用户交互

imgView.userInteractionEnabled = YES;

#if 0  /*轻拍tap*/

// 创建对象

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

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

//添加手势

[imgView addGestureRecognizer:tap];

//内存管理

[tap release];

//点击次数 几次才能识别

tap.numberOfTapsRequired = 2;

//手指个数

tap.numberOfTouchesRequired = 2;

#endif

#if 0/* 长按 longPress*/

UILongPressGestureRecognizer *tap1 = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction1:)];

[imgView addGestureRecognizer:tap1];

[tap1 release];

//长按时间

tap1.minimumPressDuration = 1;

#endif

#if 0

/*旋转rotation*/

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

[imgView addGestureRecognizer:rotation];

[rotation release];

#endif

#if 0

/*捏合pinch*/

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

[imgView addGestureRecognizer:pinch];

[pinch release];

#endif

#if 1

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];

[imgView addGestureRecognizer:pan];

[pan release];

}

#endif

#pragma mark - 轻拍tap

-(void)tapAction:(UITapGestureRecognizer *)tap{

NSLog(@"轻拍");

}

-(void)tapAction1:(UILongPressGestureRecognizer *)tap1{

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

//通过状态区分

if (tap1.state == UIGestureRecognizerStateBegan) {

NSLog(@"长按");

}

}

#pragma mark -  旋转rotation

-(void)rotationAction:(UIRotationGestureRecognizer *)rotation{

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

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

//强制类型转换(UIImageView *)

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

//设置transform实现旋转

imgView.transform = CGAffineTransformMakeRotation(rotation.rotation);

NSLog(@"旋转");

}

#pragma  mark - 捏合pinch

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

//获取

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

//缩放scale(比例)

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

pinch.scale = 1;

NSLog(@"捏合");

}

#pragma mark -  拖拽pan

-(void)panAction:(UIPanGestureRecognizer *)pan{

NSLog(@"拖拽");

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

/*

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

}

*/

@end

相关文章

  • UI手势识别器

    - (void)viewDidLoad { [super viewDidLoad]; // Do any addi...

  • UI手势识别器

    七种手势:轻拍(tap)、长按(longPress)、旋转(rotation)、捏合(pinch)、拖拽(pan)...

  • UI手势识别器

    //七中手势:轻拍(tap) 长按(longPress) 旋转(rotation) 捏合(pinch) 拖拽(p...

  • 3.6 iOS手势识别的状态和手势识别器幕后原理

    2.2手势识别的状态和手势识别器幕后原理 (一)手势的状态 (二)离散型手势识别器和连续型手势识别器之间的对比: ...

  • Gesture手势

    手势识别器 手势识别器是对触摸事件做了封装,我们无需自己去判断某个手势是否触发,手势识别器本身起到了识别作用,我们...

  • 手势——UIGestureRecognizer

    一、简介 UIGestureRecognizer是具体手势识别器的基类。 手势识别器对象(或简单地说是手势识别器)...

  • UIGestureRecognizer

    什么是手势识别器? 手势识别器就是对触摸事件做了封装,我们不需要判断某个手势是否触发,手势识别器本身起到了识别作用...

  • 同时响应多个UIGestureRecognizer

    最近在做产品试戴,效果如下: 使用了多个手势识别器: UIRotationGestureRecognizer UI...

  • iOS手势识别

    UIGestureRecognizer手势识别器手势识别器是特殊的触摸事件UIGestureRecognizer是...

  • UIGestureRecognizer手势识别器学习笔记

    UIGestureRecognizer 具体手势识别器的基类。一个手势识别器对象,或者简单地说一个手势识别器,解耦...

网友评论

      本文标题:UI手势识别器

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