ios手势识别之拖拽

 1 #import "NJViewController.h"
 2 
 3 @interface NJViewController ()
 4 @property (weak, nonatomic) IBOutlet UIView *customView;
 5 
 6 @end
 7 
 8 @implementation NJViewController
 9 
10 - (void)viewDidLoad
11 {
12     [super viewDidLoad];
13     UIPanGestureRecognizer  *pan = [[UIPanGestureRecognizer alloc] init];
14     [self.customView addGestureRecognizer:pan];
15     
16     [pan addTarget:self action:@selector(panView:)];
17 }
18 
19 - (void)panView:(UIPanGestureRecognizer *)pan
20 {
21     // 返回的值是以手指按下的点为原点
22     // 1 2 3 4 5
23     CGPoint point = [pan translationInView:pan.view];
24     
25     NSLog(@"拖拽事件 %@", NSStringFromCGPoint(point));
26     CGPoint temp = self.customView.center;
27     temp.x += point.x;
28     temp.y += point.y;
29     self.customView.center = temp;
30     
31     [pan setTranslation:CGPointZero inView:pan.view];
32 }
33 
34 @end

 

转载于:https://www.cnblogs.com/PJHome/p/5154357.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值