2011-09-24 21 views
0

我已經制作了這樣的UIPanRecognizer。UIPanRecognizer不起作用。我的觀點從未重繪

- (void)pan:(UIPanGestureRecognizer *)gesture 
{ 
    if ((gesture.state == UIGestureRecognizerStateChanged) || 
     (gesture.state == UIGestureRecognizerStateEnded)) { 
     CGPoint translation = [gesture translationInView:self]; 
     self.origin = CGPointMake(
     self.origin.x+translation.x,self.origin.y+translation.y); 
     [gesture setTranslation:CGPointZero inView:self]; 
} 

}

不過我的看法永遠不會被重繪,這意味着...我的drawRect不會被再次調用。有人試過這個?

在我的viewController我有這個

UIGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.graphView action:@selector(pan:)]; 
[self.graphView addGestureRecognizer:pan]; 
[self updateUI]; 

我updateUI是

- (void)updateUI { [self.graphView setNeedsDisplay]; } 
+0

我看不出任何理由爲什麼這段代碼應該觸發重繪。 – Eiko

+0

編輯我的帖子s – WYS

回答

1

當您將手勢識別到視圖要調用的方法updateUI。您應該在回撥方式pan:中執行此操作。

此外,你正在泄漏內存。在分配並添加UIGestureRecognizer到視圖後,您應該release它。

+0

但我updateUI是在我的viewcontroller和我的鍋:是在我的graphView。 我已經發布了它,我只是沒有發佈那部分代碼:) – WYS

+0

哦,謝謝你,我現在把[self setNeedsDisplay]放在我的平臺上重新繪製: – WYS

+0

考慮一旦系統接受答案讓你做到這一點。 – Mundi