0

下面创建一个移动整个视图的手势识别器:

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?

4

1 回答 1

0

不会:

self.theSubview.center = CGPointMake(self.theSubview.center.x + translation.x, 
                                     self.theSubview.center.y + translation.y);

做伎俩?

于 2012-07-20T22:07:47.450 回答