@interface NJViewController () @property (weak, nonatomic) IBOutlet UIView *customView; @end @implementation NJViewController - (void)viewDidLoad { [super viewDidLoad]; UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] init]; [self.customView addGestureRecognizer:pan]; [pan addTarget:self action:@selector(panView:)]; } - (void)panView:(UIPanGestureRecognizer *)pan { // 返回的值是以手指按下的点为原点 // 1 2 3 4 5 CGPoint point = [pan translationInView:pan.view]; NSLog(@"拖拽事件 %@", NSStringFromCGPoint(point)); CGPoint temp = self.customView.center; temp.x += point.x; temp.y += point.y; self.customView.center = temp; // 理解不了就记住就OK [pan setTranslation:CGPointZero inView:pan.view]; }