码迷,mamicode.com
首页 > 移动开发 > 详细

ios手势识别之拖拽

时间:2016-01-24 00:30:14      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:

 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

 

ios手势识别之拖拽

标签:

原文地址:http://www.cnblogs.com/PJHome/p/5154357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!