iOS中的各种手势

 

 UIImageView *imageView = [[UIImageViewalloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width,self.view.frame.size.height)];

    imageView.backgroundColor = [UIColorgreenColor];

    

    imageView.image = [UIImageimageNamed:@"/Users/dllo/Desktop/G[E@OFJNXNW(Y$_OIVOLH9L.jpg"];

    imageView.contentMode =UIViewContentModeScaleAspectFill;

    imageView.userInteractionEnabled =YES;

    [self.viewaddSubview:imageView];

    [imageViewrelease];

    

//    1.点击手势(tap

    UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(tapClick:)];

//    执行方法需要点击的次数

    tap.numberOfTapsRequired =2;

//    需要几个手指点击

    tap.numberOfTouchesRequired =1;

    [imageViewaddGestureRecognizer:tap];

    [taprelease];


- (void)tapClick:(UITapGestureRecognizer *)tap {

    NSLog(@"点击手势");

}




//    2.长按手势 (longpress)

    UILongPressGestureRecognizer *lon = [[UILongPressGestureRecognizeralloc] initWithTarget:selfaction:@selector(longPress:)];

//  默认0.5 -- 长按需要的时间

    lon.minimumPressDuration =3;

//    长按判定中允许用户手指移动的距离

    lon.allowableMovement =100;

    lon.numberOfTouchesRequired =1;

    [imageViewaddGestureRecognizer:lon];

    [lonrelease];


- (void)longPress:(UILongPressGestureRecognizer *)lon {

    NSLog(@"长按手势");

}



//    3.旋转手势(rotation)

    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizeralloc] initWithTarget:selfaction:@selector(rotationPress:)];

    [imageViewaddGestureRecognizer:rotation];

    [rotationrelease];


- (void)rotationPress:(UIRotationGestureRecognizer *)rontation {

    NSLog(@"旋转手势");

    UIView *imageV = rontation.view;

    imageV.transform = CGAffineTransformRotate(imageV.transform, rontation.rotation);

    rontation.rotation = 0;

}



    

//    4.捏合

    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizeralloc] initWithTarget:selfaction:@selector(pinchPress:)];

    [imageViewaddGestureRecognizer: pinch];

    [pinchrelease];


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

    NSLog(@"捏合手势");

//    获得手势所在的view

    UIView *imageV = pinch.view;

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

    pinch.scale = 1;

}


    

//    5.平移

    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizeralloc] initWithTarget:selfaction:@selector(panPress:)];

    [imageViewaddGestureRecognizer:pan];

    [panrelease];


- (void)panPress:(UIPanGestureRecognizer*)pan {

   NSLog(@"平移手势");

   UIView *imageV = pan.view;

   CGPoint point = [pan translationInView:imageV];

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

   [pan setTranslation:CGPointZeroinView:imageV];

}


//    6.轻扫

    UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizeralloc] initWithTarget:selfaction:@selector(swipePress:)];

    [imageViewaddGestureRecognizer:swipe];

    [swiperelease];


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

    NSLog(@"轻扫手势");

}



    

//    7.屏幕边缘轻扫识别器

    UIScreenEdgePanGestureRecognizer *screen = [[UIScreenEdgePanGestureRecognizeralloc] initWithTarget:selfaction:@selector(screenPress:)];

  

- (void)screenPress:(UIScreenEdgePanGestureRecognizer *)screen {

   NSLog(@"屏幕边缘");

}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值