2013-07-21 23 views
1

我需要添加UIPanGestureRecognizer才能水平滑動3個視圖。 如何將UIPangesture僅水平添加到UIView?僅在iPhone上水平添加UIPanGesture

+0

不是UISwipeGesture適合您的目的嗎?它有一個與你需要的相關的方向屬性。 – zambrey

回答

4

當您使用平移手勢識別器,你通常有一些代碼,看起來是這樣的:

CGPoint translate = [sender translationInView:self.view]; 
    CGRect newFrame = self.currentViewFrame; 
    newFrame.origin.x += translate.x; 
    newFrame.origin.y += translate.y; 
    self.touched.frame = newFrame; // touched is the view I'm dragging 

如果你只是離開了線,newFrame.origin.y + = translate.y,然後它只會在水平方向上平移。

+0

謝謝,它正常工作!我只改變它:'newFrame.origin.x = translate.x;'但現在沒關係。 謝謝! – Bellots