- (void)viewDidLoad {
[super viewDidLoad];
创建一个长按手势
// UILongPressGestureRecognizer *longPG = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPG)];
添加手势
// [self.redView addGestureRecognizer:longPG];
//
// 创建一个缩放手势
// UIPinchGestureRecognizer *pinchPG = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchPG:)];
添加缩放手势
// [self.redView addGestureRecognizer:pinchPG];
创建一个点按手势
// UITapGestureRecognizer *tapPG = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPG:)];
//
添加点按手势
// [self.redView addGestureRecognizer:tapPG];
创建拖动手势
// UIPanGestureRecognizer *panPG = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panPG:)];
添加拖动手势
// [self.redView addGestureRecognizer:panPG];
创建一个旋转手势
// UIRotationGestureRecognizer *rotePG = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rote:)];
添加一个旋转手势
// [self.redView addGestureRecognizer:rotePG];
// 创建一个轻扫手势
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
// 添加一个轻扫手势
[self.redView addGestureRecognizer:swipe];
}
// 实现轻扫手势 默认是向右时,调用此方法
- (void)swipe:(UISwipeGestureRecognizer *)swipe
{
NSLog(@"%s",__func__);
}
// 实现旋转手势
- (void)rote:(UIRotationGestureRecognizer *)rotePG
{
self.redView.transform = CGAffineTransformRotate(self.redView.transform, rotePG.rotation);
// 复位
[rotePG setRotation:0];
}
// 实现拖动手势
- (void)panPG:(UIPanGestureRecognizer *)panPG
{
CGPoint transP = [panPG translationInView:self.redView];
self.redView.transform = CGAffineTransformTranslate(self.redView.transform, transP.x, transP.y);
// 复位
[panPG setTranslation:CGPointZero inView:self.redView];
}
// 点按手势
- (void)tapPG:(UITapGestureRecognizer *)tapPG
{
NSLog(@"%s",__func__);
}
// 缩放手势
- (void)pinchPG:(UIPinchGestureRecognizer *)pinchPG
{
self.redView.transform = CGAffineTransformScale(self.redView.transform, pinchPG.scale, pinchPG.scale);
// 复位
[pinchPG setScale:1];
}
// 实现长按手势
- (void)longPG
{
NSLog(@"%s",__func__);
}