ios 手势使用

2016-07-25  本文已影响32人  dicesc
手势的分类

(一) 手势分类
state 状态 (UIGestureRecognizerStateBegan Change ended)不同状态
view当前被点击的View


拖拽简单使用

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *purpleView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

-(void)viewDidLoad {
[super viewDidLoad];

_imageView.userInteractionEnabled = YES;
_imageView.multipleTouchEnabled = YES;

// 轻触

// 1. 实例化手势识别对象
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];


[_imageView addGestureRecognizer:pan];

}

// 3. 实现监听方法
-(void)pan:(UIPanGestureRecognizer *)pan {

CGPoint translatePoint = [pan translationInView:pan.view];

// 让view进行移动
pan.view.transform = CGAffineTransformTranslate(pan.view.transform,translatePoint.x, translatePoint.y);


[pan setTranslation:CGPointZero inView:pan.view];

}

@end


旋转的简单使用

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIView *purpleView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;

@end

@implementation ViewController

-(void)viewDidLoad {
[super viewDidLoad];

_imageView.userInteractionEnabled = YES;
_imageView.multipleTouchEnabled = YES;

// 轻触

// 1. 实例化手势识别对象
UIRotationGestureRecognizer *rotate = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];


[_imageView addGestureRecognizer:rotate];

}

// 3. 实现监听方法
-(void)rotate:(UIRotationGestureRecognizer *)rotate {

NSLog(@"------ %f", rotate.rotation);


// 如果手指头停止旋转, 当再次旋转的时候 就会从0 开始

// rotate.view.transform = CGAffineTransformMakeRotation(rotate.rotation);

rotate.view.transform = CGAffineTransformRotate(rotate.view.transform, rotate.rotation);

// 每一次旋转之后, 旋转的角度都从0开始计算
rotate.rotation = 0;

}

@end


其他手势都是类似步骤,根据上面的关键字都可以提示的.

上一篇 下一篇

猜你喜欢

热点阅读