UIPanGestureRecognizer类中translationInView

UIPanGestureRecognizer主要用于拖动,比如桌面上有一张图片uiimageview,你想让它由原始位置拖到任何一个位置,就是图片跟着你的手指走动,那么就需要用到该类了。

以下代码表示给一个图片视图指定一个UIPanGestureRecognizer手势当该图片捕获到用户的拖动手势时会调用回调函数handlePan

 

C代码   收藏代码
  1. UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];  
  2.     [self.imgView setUserInteractionEnabled:YES];  
  3.     [self.imgView addGestureRecognizer:pan];  
  4.     [pan release];  

 handlePan函数代码如下:

 

C代码   收藏代码
  1. - (void) handlePan: (UIPanGestureRecognizer *)rec{  
  2.     NSLog(@"xxoo---xxoo---xxoo");        
  3.     CGPoint point = [rec translationInView:self.view];  
  4.     NSLog(@"%f,%f",point.x,point.y);  
  5.     rec.view.center = CGPointMake(rec.view.center.x + point.x, rec.view.center.y + point.y);  
  6.     [rec setTranslation:CGPointMake(0, 0) inView:self.view];  
  7. }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值