uipangeSturercogniser的问题
-
25-10-2019 - |
题
使用Xcode 4.2并试图与Uigesturercogniser掌握。到目前为止,一切似乎都进展顺利,但仍有一些问题。
当我使用滑动手势识别器时,一切都很好,它将识别所有不同方向的刷动,并且会连续地进行。我现在的问题是,当使用锅手势识别器时,它识别出第一个锅轻扫良好,但随后只是拒绝接受任何进一步的手势。因此,我可以根据需要将物品移动一次,但是在此之后,什么都不做。
我设置了我的手势如下:
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和Sidepanel是与Uiview在我的界面顶部覆盖的IBOUTLET。
如果有人能阐明此信息,那将是很棒的,因为我绝对不知道发生了什么!
谢谢,
马特
解决方案
首先我会检查
if (recognizer.state == UIGestureRecognizerStateChanged)
在进行翻译之前(还有许多其他可能的状态不能证明您采取任何行动)。另外,我将使用UipangeSturerEncognizer方法重置每个回调的每次回调的翻译
- (void)setTranslation:(CGPoint)translation inView:(UIView *)view
如果手势识别器停止,则可能是另一个手势识别器正在干扰它。您还有一个活跃的uiswipegesturerognizer吗?如果是这样,您可能应该停用其中之一。您也可以查看此方法
- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer
它允许您指定应优先考虑哪个识别器。
不隶属于 StackOverflow