定义部分
//1.轻拍手势
// UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changViewBackgroundColor:)];
// tapGesture.numberOfTapsRequired = 2;//需要点击两次触法
// tapGesture.numberOfTouchesRequired = 2;//需要两根手指点击触法
// [aView addGestureRecognizer:tapGesture];
//2.长按手势
// UILongPressGestureRecognizer *longPerss = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(changViewBackgroundColor:)];
// longPerss.minimumPressDuration = 2.0;//设置长按触发的最短时间
// [aView addGestureRecognizer:longPerss];
//长按手势在结束的时候会再次调用该方法,设置state值设为只在开始触法时调用该方法。
// if (tap.state == UIGestureRecognizerStateBegan)
//3.轻扫手势
// UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(changViewBackgroundColor:)];
// swipeGesture.direction = UISwipeGestureRecognizerDirectionUp;//设置触法的方向为从下到上,初始为从左至右
// [aView addGestureRecognizer:swipeGesture];
//4.拖动手势
// UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
// [aView addGestureRecognizer:panGesture];
//5.捏合手势
// UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
// [aView addGestureRecognizer:pinchGesture];
//6.旋转手势
UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
[aView addGestureRecognizer:rotationGesture];
实现部分
//- (void)changViewBackgroundColor:(UISwipeGestureRecognizer *)tap
//{
// UIView *aView = tap.view;
// aView.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
// NSLog(@"tap");
//}
------------------------------------------------------------------------我是分割线---------------------------------------------------------------------
//- (void)panAction:(UIPanGestureRecognizer *)panGesture
//{
// //获得的偏移量是基于手指触摸初始点的偏移量
// CGPoint offsetPoint = [panGesture translationInView:panGesture.view];
// NSLog(@"offset point = %@",NSStringFromCGPoint(offsetPoint));
// //更改View的transform
// panGesture.view.transform = CGAffineTransformMakeTranslation(offsetPoint.x, offsetPoint.y);
//}
------------------------------------------------------------------------我是分割线---------------------------------------------------------------------
//- (void)pinchAction:(UIPinchGestureRecognizer *)pinch
//{
// NSLog(@"scale = %f",pinch.scale);
// //让View缩放
// pinch.view.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
//}
------------------------------------------------------------------------我是分割线---------------------------------------------------------------------
- (void)rotationAction:(UIRotationGestureRecognizer *)rotation
{
NSLog(@"rotation = %f",rotation.rotation);
//让View旋转
rotation.view.transform = CGAffineTransformMakeRotation(rotation.rotation);
}