2013-08-02 81 views
0

我有五個視圖,我已經應用UIPanGestureRecognizer放置在距離彼此有一個相同的Y-asix從頂部(框類型形狀)。一次限制一個視圖平移

我在x軸上拖動視圖進行平移。問題是我可以拖動多個視圖與多個觸摸。我想限制一次拖動一個視圖。

我嘗試使用UIPanGestureRecognizer財產

pan.maximumNumberOfTouches=1; 

但這是隻是單一視圖。有任何想法嗎?

回答

1

試試這個太,

比方說你有一個的viewController的視圖中添加所有這五個視圖。然後執行以下操作;

myViewController.view.multipleTouchEnabled = NO; 

這使MAINVIEW僅處理第一觸摸,只有這第一個一碰就會流下來的層次結構(即以子視圖及其gestureRecognizers)

希望這個作品。

Alernate:

  1. 在MAINVIEW或mainViewController持有的5次的接口定義此。

    @property(nonatomic,retain)UIPanGestureRecognizer * currentRecognizer;

    1. 然後應用下面的代碼。

- (無效)on_pan_gesture:(UIPanGestureRecognizer *)panGestureRecognizer
{

如果(!self.currentRecognizer =零& & [self.currentRecognizer isEqual:方法panGestureRecognizer])

 { 
      //do the task of the selected gesture recognizer 
      //this recognizer will be active till the touches are not ended or cancelled. 
      //hence on the first recognizer will work. 
     } 
     else 
     { 
      //if there is not currentRecognizer then set this recognizer to be current. 
      self.currentRecognizer = panGestureRecognizer; 
     } 
    } 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    self.currentRecognizer = nil; 
} 

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    self.currentRecognizer = nil; 
} 
+0

multipleTouchEnabled已被設置爲NO。 – Hassy

+0

檢查我的編輯.. – CodenameLambda1

0

使用手勢識別委託方法

gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: 

,使其返回NO。

相關問題