首页 > 移动平台 > 详细

ios手势识别之拖拽

时间:2016-01-24 00:27:12      阅读:310      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!