0

使用XCode 4.2並試圖與UIGestureRecognisers握手。到目前爲止,所有的事情似乎都很順利,但我仍然有一些問題。UIPanGestureRecogniser存在問題

當我使用滑動手勢識別器時,一切都很好,它會識別所有不同方向的滑動,並且會一直這樣做。我現在的問題是,當使用平移手勢識別器時,它會識別出第一個平移滑動杆罰款,但只是拒絕接受任何進一步的手勢。所以我可以根據需要將物品移動一次,但在此之後,什麼都不能做。

設置我的姿態,如下所示:

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"); 
    } 
} 
} 

bodyPanel,topPanel和側面板被IBOutlets連接的UIView的重疊在我的界面上方.xib

如果有人能夠揭示這些信息,這將是偉大的原因,我絕對不知道發生了什麼!

感謝,

馬特

回答

1

首先,我會檢查

if (recognizer.state == UIGestureRecognizerStateChanged) 

做你的翻譯之前(有會沒有理由採取任何措施的許多其他可能的狀態)。另外我想在每一個回調給您正在使用的UIPanGestureRecognizer方法

- (void)setTranslation:(CGPoint)translation inView:(UIView *)view 

如果手勢識別停止它可能是另一種姿態識別與干擾它積累他們重新翻譯。你還有一個活躍的UISwipeGestureRecognizer嗎?如果是這樣,你應該停用其中的一個。你也可以看看這個方法

- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer 

它允許你指定哪個識別器應該被給予優先權。