1.轻拍手势
- (void)tapGestureRecognizer
{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
[tap addTarget:self action:@selector(tapActipon:)];
[_bgView addGestureRecognizer:tap];
}
- (void)tapActipon:(UITapGestureRecognizer *)tap
{
NSLog(@"tap");
}
2.长按手势
- (void)longPressRecognizer
{
UILongPressGestureRecognizer *press = [[UILongPressGestureRecognizer alloc] init];
[press addTarget:self action:@selector(longPressAction:)];
[_bgView addGestureRecognizer:press];
}
- (void)longPressAction:(UILongPressGestureRecognizer *)press
{
NSLog(@"press");
}
3.轻扫手势
-(void)swipeGestureRecognizer
{
UISwipeGestureRecognizer *swipe =[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
//一个清扫手势 只能有两个方向(上和下) 或者 (左或右)
//如果想支持上下左右清扫 那么一个手势不能实现 需要创建两个手势
swipe.direction =UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight;
[_bgView addGestureRecognizer:swipe];
}
-(void)swipeAction:(UISwipeGestureRecognizer *)swipe
{
NSLog(@"swipe");
}
4.平移手势
-(void)panGestureTecognizer
{
UIPanGestureRecognizer *pan =[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
//添加到指定视图
[_bgView addGestureRecognizer:pan];
}
-(void)panAction:(UIPanGestureRecognizer *)pan
{
CGPoint position =[pan translationInView:_bgView];
//通过stransform 进行平移交换
_bgView.transform = CGAffineTransformTranslate(_bgView.transform, position.x, position.y);
//将增量置为零
[pan setTranslation:CGPointZero inView:_bgView];
}
5.捏合手势
-(void)pinchGestureRecognizer
{
UIPinchGestureRecognizer *pinch =[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
//添加到指定视图
[_bgView addGestureRecognizer:pinch];
}
-(void)pinchAction:(UIPinchGestureRecognizer *)pinch
{
//通过 transform(改变) 进行视图的视图的捏合
_bgView.transform =CGAffineTransformScale(_bgView.transform, pinch.scale, pinch.scale);
//设置比例为 1
pinch.scale = 1;
}
6.旋转手势
-(void)rotationGestureRecognizer
{
UIRotationGestureRecognizer *rotation =[[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
//添加到指定的视图
[_bgView addGestureRecognizer:rotation];
}
-(void)rotationAction:(UIRotationGestureRecognizer *)rote
{
//通过transform 进行旋转变换
_bgView.transform = CGAffineTransformRotate(_bgView.transform, rote.rotation);
//将旋转角度 置为 0
rote.rotation = 0;
}
7.边缘手势
-(void)screenEdgePanGestureRecognizer
{
UIScreenEdgePanGestureRecognizer *screenPan = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenPanAction:)];
[_bgView addGestureRecognizer:screenPan];
}
-(void)screenPanAction:(UIScreenEdgePanGestureRecognizer *)screenPan
{
NSLog(@"边缘");
}