2013-08-02 45 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。

相关问题