UIPanRecognizer不起作用。我的观点从未重新绘制过

时间:2011-09-24 11:46:00

标签: objective-c ios xcode

我已经制作了这样的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]; } 

1 个答案:

答案 0 :(得分:1)

将手势识别器附加到视图时,您正在调用updateUI方法。您应该在回调方法pan:中执行此操作。

另外,你正在泄漏记忆。分配UIGestureRecognizer并将其添加到视图后,您应该release它。