UI14手势

//

//  RootViewController.m

//  UI14手势

//

//  Created by focus on 2017/1/22.

//  Copyright © 2017年 focus. All rights reserved.

//

 

#import "RootViewController.h"

 

@interface RootViewController ()

 

@end

 

@implementation RootViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    UIImageView * imageV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 380, 510)];

    imageV.image =[UIImage imageNamed:@"timg.JPEG"];

    //打开用户交互事件

    imageV.userInteractionEnabled = YES;

    [self.view addSubview:imageV];

    

    // 六大手势

    //1.点击手势

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

    //控制点击次数

    tap.numberOfTapsRequired = 3;

    // 把手势添加到图片上

    //[imageV addGestureRecognizer:tap];

    

    //2.长按手势

    UILongPressGestureRecognizer * longP = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressMe:)];

    //长按时间

    longP.minimumPressDuration = 3;

    //控制长按过程过手指允许移动的范围

    longP.allowableMovement = 50;

    //[imageV addGestureRecognizer:longP];

    

    //3.轻扫

    UISwipeGestureRecognizer *swip = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipMe:)];

    // 指定方向 每个声明对象,指定方向只能触动一个方向事件

    swip.direction = UISwipeGestureRecognizerDirectionLeft;

    //[imageV addGestureRecognizer:swip];

    

    //4.缩放手势

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

    [imageV addGestureRecognizer:pinch];

    

    //5.拖拽手势

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

    [imageV addGestureRecognizer:pan];

    

    

    //6.旋转手势

    UIRotationGestureRecognizer * rotaion = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationMe:)];

    [imageV addGestureRecognizer:rotaion];

    

    //屏幕边界手势

//    UIScreenEdgePanGestureRecognizer

}

 

//旋转手势对应的方法

-(void) rotationMe:(UIRotationGestureRecognizer *)rot {

    //获取手势所在的视图

    UIImageView *imagev = (UIImageView *)rot.view;

    //矩阵变化

    imagev.transform = CGAffineTransformRotate(imagev.transform, rot.rotation);

    

    //移动之后的坐标 == 等同移动之后还原

    rot.rotation = 0;

    

}

 

 

//拖拽手势对应的方法

-(void) panMe:(UIPanGestureRecognizer *)p {

    //获取手势所在的视图

    UIImageView * imagev = (UIImageView *)p.view;

    //矩阵变化

    CGPoint point =[p translationInView:imagev];

    imagev.transform = CGAffineTransformTranslate(imagev.transform, point.x, point.y);

    

    //移动之后的坐标 == 等同移动之后还原

    [p setTranslation:CGPointZero inView:imagev];

}

 

 

 

//缩放手势对应的方法

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

    //获取手势所在的视图

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

    //矩阵变换

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

    //缩放比例参照最开始图片的大小

    pinch.scale =1;

    

}

 

 

//轻扫手势对应的方法

-(void) swipMe:(UISwipeGestureRecognizer *)swipe {

    if(swipe.direction== UISwipeGestureRecognizerDirectionLeft){

        NSLog(@"向左扫<...");

    }else if(swipe.direction == UISwipeGestureRecognizerDirectionDown){

        NSLog(@"向下扫___");

    }

}

 

 

-(void) longPressMe:(UILongPressGestureRecognizer *)longPre {

    if(longPre.state==UIGestureRecognizerStateBegan) {

        NSLog(@"长按开始");

    }else if(longPre.state == UIGestureRecognizerStateChanged){

        NSLog(@"手抖");

    }else if(longPre.state == UIGestureRecognizerStateEnded) {

        NSLog(@"长按结束");

    }

    

}

 

 

-(void)tapMe {

    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

 

转载于:https://my.oschina.net/VincentOSC/blog/829332

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值