IOS-六种手势的简单使用

#pragma--------  1.点击

    UITapGestureRecognizer  *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)]; // 初始化

    tap.numberOfTouchesRequired = 1;//   默认值是1 设置点击手指的个数

    tap.numberOfTapsRequired =1; // 设置点击的次数

    [self.view addGestureRecognizer:tap]; // 添加到view视图

-(void)tapAction:(UITapGestureRecognizer *)sender // 单击手势的方法

{

    //    self.view.backgroundColor = [UIColor redColor];

    imageView.transform = CGAffineTransformIdentity;//恢复视图的初始状态

    CGPoint tapLoc = [sender locationInView:self.view];

    NSLog(@"%f %f",tapLoc.x,tapLoc.y);

    // 点击的位置  设置图片视图的中心点

    [UIView animateWithDuration:0.5 animations:^{

        imageView.center = tapLoc;

    }]; //写动画

}



#pragma--------2长按

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

    longPress.minimumPressDuration = 2;//设置长按最小时间

    [self.view addGestureRecognizer:longPress]; // 把手势添加到view视图上

-(void)longPress:(UILongPressGestureRecognizer *)sender

{

    self.view.backgroundColor = [UIColor grayColor];

    CGPoint tapLoc = [sender locationInView:self.view];

    NSLog(@"%f %f",tapLoc.x,tapLoc.y);

    // 点击的位置  设置图片视图的中心点

    

    [UIView animateWithDuration:2 animations:^{

        imageView.center = tapLoc;

    }]; //写动画

}

#pragma--------3.拖拽

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

    pan.minimumNumberOfTouches = 2; // 设置最小的手指个数

    pan.maximumNumberOfTouches = 2; // 设置最大的手指个数

    [self.view addGestureRecognizer:pan];

- (void)Pan:( UIPanGestureRecognizer *)sender

{

    self.view.backgroundColor = [UIColor whiteColor];

    CGPoint tapLoc = [sender locationInView:self.view];

    NSLog(@"%f %f",tapLoc.x,tapLoc.y);

    imageView.center = tapLoc;

}



#pragma--------4.轻扫

    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(Swipe:)];

    swipe.direction =  UISwipeGestureRecognizerDirectionLeft;//设置轻扫的方向

    [self.view addGestureRecognizer:swipe];//添加到view视图上

- (void)Swipe:(UISwipeGestureRecognizer *)sender

{

    self.view.backgroundColor = [UIColor orangeColor];

    self.view.frame =CGRectMake(CGRectGetWidth([UIScreen mainScreen].bounds), 0,CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds));

    [UIView animateWithDuration:2 animations:^{

        self.view.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds) ,CGRectGetHeight([UIScreen mainScreen].bounds));

    }];

    

}



#pragma--------5.捏合

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

    [self.view addGestureRecognizer:pinch];

- (void)pinch:(UIPinchGestureRecognizer *)sender

{

    //    通过手势得到变化比例 让imageView形态发生改变

    imageView.transform = CGAffineTransformScale(imageView.transform, sender.scale, sender.scale) ;

    imageView.center = self.view.center;

}



#pragma--------6.旋转

    UIRotationGestureRecognizer *rotion = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector( Rotion:)];

    [self.view addGestureRecognizer:rotion];

    // Do any additional setup after loading the view, typically from a nib.

-(void)Rotion:( UIRotationGestureRecognizer *)sender

{

    imageView.transform = CGAffineTransformMakeRotation(sender.rotation);//通过旋转手势让图片进行相同的变形

}








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值