UIPanGestureRecognizer不能在UIImageView上工作

时间:2012-07-09 21:25:28

标签: ios drag-and-drop uiimageview uipangesturerecognizer

好吧,我们的想法是在带有字符的小圆圈上实现拖放功能。看似简单,但我无法立刻做到这一点。问题是代表小圆圈的UIImageView根本不会对平底锅做出反应。这是我写的代码:

- (void)createLiterasAndPlacesForThemForCard:(UIView *)frontCard andWord:(NSString *)word;
for (int i=0; i<[word length]; i++) {
    UIImageView * oneChar = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LetterFull"]];
    oneChar.frame = CGRectMake(26+i*24, 175, 23, 24);
    oneChar.backgroundColor = [UIColor clearColor];
    oneChar.userInteractionEnabled = YES;
    UIPanGestureRecognizer * oneCharPanGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(move:)];
    [oneCharPanGestureRecognizer setMinimumNumberOfTouches:1];
    [oneCharPanGestureRecognizer setMaximumNumberOfTouches:1];
    [oneCharPanGestureRecognizer setDelegate:self];
    [oneChar addGestureRecognizer:oneCharPanGestureRecognizer];
    [frontCard addSubview:oneChar];
}

这是层次结构 - 我有一个上面称为“self”的viewController,它包含一个包含一些卡片的滚动视图,每张卡片都有可以拖动的小圆圈。我在设置代表的行上收到警告,但我想这不是一个实际问题。

以下是“move:”方法的代码:

- (void)move:(id)sender
{
    NSLog(@"THE PAN OCCURED");
    float firstX;
    float firstY;

    CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];

    if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {

        firstX = [[sender view] center].x;
        firstY = [[sender view] center].y;
    }

    translatedPoint = CGPointMake(firstX+translatedPoint.x, firstY+translatedPoint.y);
    [[sender view] setCenter:translatedPoint];
}

我看不到任何对平底锅的反应 - 无论是在控制台还是在屏幕上。请帮助我,我自己找不到解决方案,我已经启用了userInteraction并且没有帮助。

0 个答案:

没有答案