下面创建一个移动整个视图的手势识别器:
UIPanGestureRecognizer * recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
recognizer.delegate = self;
[self.view addGestureRecognizer:recognizer];
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}
但我只想移动其中一个子视图。我不能这样做:
[self.theSubview addGestureRecognizer:recognizer];
因为我想识别整个屏幕上的手势。应该移动的对象可能很小,我不想强迫用户“抓住”它。如何修改处理程序方法以仅移动 Subview?