我有五个视图,我已经应用了UIPanGestureRecognizer
放置了彼此相距一段距离,从顶部开始具有相同的Y-asix(盒式形状)。
我在x轴上平移拖动视图。问题是我可以通过多次触摸拖动多个视图。我想限制一次拖动一个视图。
我尝试使用UIPanGestureRecognizer
属性
pan.maximumNumberOfTouches=1;
但这仅适用于单一视图。任何想法?
答案 0 :(得分:1)
试试这个,
假设您在viewController的视图中添加了所有这五个视图。然后执行以下操作;
myViewController.view.multipleTouchEnabled = NO;
这使得mainView只处理第一次触摸,只有第一次触摸将沿着层次结构向下流动(即到子视图及其gestureRecognizers)
希望这有效。
Alernate:
在包含5个视图的mainView或mainViewController的界面中定义它。
@property(nonatomic,retain)UIPanGestureRecognizer * currentRecognizer;
- (void)on_pan_gesture:(UIPanGestureRecognizer *)panGestureRecognizer
{
if(self.currentRecognizer!= nil&& [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;
}
答案 1 :(得分:0)
使用手势识别器的委托方法
gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
让它返回NO。