ios手势识别之拖拽
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于ios手势识别之拖拽的主要内容,如果未能解决你的问题,请参考以下文章