UIGestureRecognizer的一些简单的方法总结

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.


    

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 335, 627)];

    imageView.backgroundColor = [UIColor yellowColor];

    [self.view addSubview:imageView];

    //打开imageView的用户交互属性, 让他可以响应用户点击事件

    imageView.userInteractionEnabled = YES;

    [imageView release];

    

    UIImage *image = [UIImage imageNamed:@"2.jpg"];

    imageView.image = image;

    

    //    手势的种类

    //    1. 点击

    //    2. 长按

    //    3. 捏合

    //    4. 轻扫

    //    5. 拖拽

    //    6. 旋转

    //    7. 屏幕边缘拖拽

    //1. 点击(tap)

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

//    //执行方法需要点击几次

//    tap.numberOfTapsRequired = 2;

//    //需要几根手指头点击

//    tap.numberOfTouchesRequired = 2;

//    //view添加一个点击手势

//    [imageView addGestureRecognizer:tap];

//    [tap release];

    //2. 长按

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

//    //判定为长按手势需要的时间, 默认0.5, 按多长时间算长按

//    longPress.minimumPressDuration = 3;

//    //在判定过程中, 允许用户手指移动的距离

//    longPress.allowableMovement = 10;

//    [imageView addGestureRecognizer:longPress];

//    [longPress release];

    //3, 捏合

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

//    [imageView addGestureRecognizer:pinch];

//    [pinch release];

    //4. 轻扫(swipe)

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

//    //设置检测的方向, 这个是向左

//    swipe.direction = UISwipeGestureRecognizerDirectionLeft;

//    [imageView addGestureRecognizer:swipe];

//    [swipe release];

    //5.拖拽

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

//    [imageView addGestureRecognizer:pan];

//    [pan release];

    //6.旋转

//    UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationAction:)];

//    [imageView addGestureRecognizer:rotation];

//    [rotation release];

    //屏幕边缘拖拽

    UIScreenEdgePanGestureRecognizer *screen = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(aaa:

                                                                                                                              )];

    [imageView addGestureRecognizer:screen];

    [screen release];

    

    

    

}

//点击执行的方法

- (void)tapAction:(UITapGestureRecognizer *)tap

{

    NSLog(@"点击手势");

    

}

//长按执行的方法

- (void)longPressAction:(UILongPressGestureRecognizer *)longPress

{

    //长按手势重写了:触摸开始. 触摸移动. 触摸结束

    //手势的状态

    if (longPress.state == UIGestureRecognizerStateBegan) {

        NSLog(@"长按开始");

    }

}

//捏合的方法

- (void)pinchAction:(UIPinchGestureRecognizer *)pinch

{

    NSLog(@"捏合");

    //获得手势所在的view

    UIView *view = pinch.view;

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

    pinch.scale = 1;

}

//轻扫的方法

- (void)swipeAction:(UISwipeGestureRecognizer *)swipe

{

    NSLog(@"轻扫");

}

//

- (void)panAction:(UIPanGestureRecognizer *)pan

{

    //获得手势所在的view

    UIView *view = pan.view;

    CGPoint p = [pan translationInView:view];

    view.transform = CGAffineTransformTranslate(view.transform, p.x, p.y);

    [pan setTranslation:CGPointZero inView:view];

    NSLog(@"拖拽");

}


- (void)rotationAction:(UIRotationGestureRecognizer *)rot

{

    

    UIView *view = rot.view;

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

    rot.rotation = 0;

    NSLog(@"旋转");

}


- (void)aaa:( UIScreenEdgePanGestureRecognizer *)aaa

{

    NSLog(@"屏幕边缘拖拽");

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值