0

下面創建一個手勢識別是移動整個視圖:對整個視圖使用UIPanGestureRecognizer移動子視圖

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]; 

因爲我想識別整個屏幕上的手勢。應該移動的對象可能很小,我不想強​​制用戶「抓」它。我如何修改處理器方法來移動子視圖?

回答

0

豈不:

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

取得成功?

相關問題