iOS UI里面五大手势使用


单击

1.1初始化以及使用:

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

   设置点击手指的个数

    tap.numberOfTouchesRequired = 1;

    

//    设置手指点击的个数

    tap.numberOfTapsRequired = 1;

    

        [self.view addGestureRecognizer:tap];

点击触发的方法:

- (void) tapAction:(UITapGestureRecognizer *) sender{

    

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

    

    iamgeView.transform = CGAffineTransformIdentity;

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

    [UIView animateWithDuration:0.5 animations:^{

        iamgeView.center = point;

    }];   

}

1.2 长按

 1.2.1:初始化以及使用:

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

longPress.minimumPressDuration = 0.5;

[self.view addGestureRecognizer: longPress];

长按触发的方法:

- (void) longPress:(UILongPressGestureRecognizer *)longPress

{

//    iamgeView.center = CGPointMake(20, 20);

//    获得手势的触摸点

    CGPoint point = [longPress locationInView:self.view];

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

    [UIView animateWithDuration:0.2 animations:^{

        iamgeView.center = point;

    }];

}



拖拽

1.初始化以及使用:

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

pan.miniNumberOfTouches = 1;

[self.view addGestureRecognizer: pan];


拖拽触发的方法:


- (void) panAction:(UIPanGestureRecognizer *) sender{

      

//     获取位置信息

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


    iamgeView.center = point;

}


清扫

1.初始化以及使用

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

swipe.direction = UISwipeGestureRecognizerDirectionLeft;

[pan requireGestureRecognizerToFail:swipe];  

用来处理拖拽和清扫手势的冲突,判断哪个手势时间段,就让哪个手势先执行

[self.view addGestureRecognizer:swipe];

拖拽触发的方法:

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

    

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

    

    [UIView animateWithDuration:1 animations:^{

        

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

    }];

}

捏合

UIPichGestureRecognizer *pich = [ [UIPichGestureRecognizer alloc] initWithTarget: self action: @selector (pichAction:)];

[self.view addGestureRecognizer:pich];

捏合触发的方法:


- (void) pichAction:(UIPinchGestureRecognizer *)sender{

    

    

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

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

    

    

}

旋转

1.初始化以及使用:

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


[self.view addGestureRecognizer: rotation];


 旋转触发的方法:

- (void) rotationAction:(UIRotationGestureRecognizer *)sender{

    

    iamgeView.transform = CGAffineTransformMakeRotation(sender.rotation);

    

    

    

    

}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值