Objective c UIPangestureRecognitor的问题

Objective c UIPangestureRecognitor的问题,objective-c,uigesturerecognizer,uipangesturerecognizer,Objective C,Uigesturerecognizer,Uipangesturerecognizer,使用XCode 4.2并努力掌握UIgestureRecognitors。到目前为止,一切似乎都进行得相当顺利,但我仍有一些问题 当我使用刷卡手势识别器时,一切都很好,它可以识别所有不同方向的刷卡,并且可以连续地识别。我现在的问题是,当使用平移手势识别器时,它会识别出第一次平移,但随后拒绝接受任何进一步的手势。所以我可以根据需要移动物品一次,但在那之后,我什么也做不了 我的姿势设置如下: UIPanGestureRecognizer *panBody = [[UIPanGestureRecogn

使用XCode 4.2并努力掌握UIgestureRecognitors。到目前为止,一切似乎都进行得相当顺利,但我仍有一些问题

当我使用刷卡手势识别器时,一切都很好,它可以识别所有不同方向的刷卡,并且可以连续地识别。我现在的问题是,当使用平移手势识别器时,它会识别出第一次平移,但随后拒绝接受任何进一步的手势。所以我可以根据需要移动物品一次,但在那之后,我什么也做不了

我的姿势设置如下:

UIPanGestureRecognizer *panBody = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panBody:)];
[bodyGestureView addGestureRecognizer:panBody];
这就是我的“panBody”方法,它可以处理所有问题:

- (void)panBody:(UIPanGestureRecognizer *)recognizer
{
CGPoint translate = [recognizer translationInView:self.view];

CGRect bodyPanelFrame = bodyPanel.frame;
bodyPanelFrame.origin.x += translate.x;
bodyPanelFrame.origin.y += translate.y;
recognizer.view.frame = bodyPanelFrame;

CGRect topPanelFrame = topPanel.frame;
topPanelFrame.origin.x += translate.x;
topPanelFrame.origin.y += translate.y;
recognizer.view.frame = topPanelFrame;

CGRect sidePanelFrame = sidePanel.frame;
sidePanelFrame.origin.x += translate.x;
sidePanelFrame.origin.y += translate.y;
recognizer.view.frame = sidePanelFrame;

NSLog(@"Panning");

if (recognizer.state == UIGestureRecognizerStateEnded)
{
    bodyPanel.frame = bodyPanelFrame;

    if((topPanel.frame.origin.x + translate.x) <= 193)
    {
        topPanel.frame = CGRectMake(topPanelFrame.origin.x, topPanel.frame.origin.y, topPanel.frame.size.width, topPanel.frame.size.height);
    }
    else
    {
        topPanel.frame = CGRectMake(193, 0, topPanel.frame.size.width, topPanel.frame.size.height);
        NSLog(@"Top panel not in frame");
    }

    if((sidePanel.frame.origin.y + translate.y) < 57)
    {
        sidePanel.frame = CGRectMake(sidePanel.frame.origin.x, sidePanelFrame.origin.y, sidePanel.frame.size.width, sidePanel.frame.size.height);
    }
    else
    {
        sidePanel.frame = CGRectMake(0, 56, sidePanel.frame.size.width, sidePanel.frame.size.height);
        NSLog(@"Side panel not in frame");
    }
}
}
-(void)panBody:(UIPangestureRecognitor*)识别器
{
CGPoint translate=[recognizer translationView:self.view];
CGRect bodyPanelFrame=bodyPanel.frame;
bodyPanelFrame.origin.x+=translate.x;
bodyPanelFrame.origin.y+=translate.y;
recognizer.view.frame=车身面板框架;
CGRect topPanelFrame=topPanel.frame;
topPanelFrame.origin.x+=translate.x;
topPanelFrame.origin.y+=translate.y;
recognizer.view.frame=topPanelFrame;
CGRect sidePanelFrame=sidePanel.frame;
sidePanelFrame.origin.x+=translate.x;
sidePanelFrame.origin.y+=translate.y;
recognizer.view.frame=侧面板框架;
NSLog(“平移”);
if(recognizer.state==UIgestureCongnizerStateEnded)
{
bodyPanel.frame=车身板框架;

如果((topPanel.frame.origin.x+translate.x)首先我会检查它

if (recognizer.state == UIGestureRecognizerStateChanged)
在进行翻译之前(有许多其他可能的状态无法证明您采取任何行动的合理性)。此外,如果您使用UIPangestureRecognitor方法累积翻译,我会在每次回调时重置翻译

- (void)setTranslation:(CGPoint)translation inView:(UIView *)view
如果手势识别器停止,则可能是另一个手势识别器正在干扰它。您是否仍有活动的UISweepGestureRecognitor?如果是,您可能应该停用其中一个。您也可以查看此方法

- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer
它允许您指定哪个识别器应具有优先级