uipangesturerecogniserの問題
-
25-10-2019 - |
質問
Xcode 4.2と協力して、UigesturerCognisersを把握しようとしています。これまでのところ、すべてがかなりうまくいっているようですが、まだいくつかの問題があります。
スワイプジェスチャー認識者を使用していたとき、すべてが順調で、すべての異なる方向のスワイプを認識し、継続的にそうします。私の問題は、パンジェスチャー認識者を使用する場合、最初のパンスワイプは正常にスワイプすることを認識しますが、それ以上のジェスチャーを受け入れることを拒否します。そのため、必要に応じてアイテムを1回移動できますが、その後は何もできません。
ジェスチャーを次のように設定します。
UIPanGestureRecognizer *panBody = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panBody:)];
[bodyGestureView addGestureRecognizer: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");
}
}
}
ボディパネル、トッパネル、サイドパネルは、私のインターフェース.xibの上部にUiviewのオーバーレイにリンクされているiboutletsです。
誰かがこの情報に光を当てることができれば、それは私が何が起こっているのか全くわからないので、それは大きなことです!!
ありがとう、
マット
解決
最初に私はそれをチェックします
if (recognizer.state == UIGestureRecognizerStateChanged)
翻訳を行う前に(行動を起こすことを正当化しない他の多くの状態があります)。また、uipangesturerecognizerメソッドを使用してそれらを蓄積している場合、すべてのコールバックで翻訳をリセットします
- (void)setTranslation:(CGPoint)translation inView:(UIView *)view
ジェスチャー認識が停止した場合、別のジェスチャー認識が妨げられている可能性があります。あなたはまだそこにアクティブなuiswipegesturerecognizerを持っていますか?もしそうなら、あなたはおそらくそれらの1つを無効にする必要があります。この方法も見ることができます
- (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer
これにより、優先順位を与える必要がある認識者を指定できます。