0

I have a very strange problem with gestures on iOS5. I have a class that inherits from the UIControl. I implement two GestureRecognizers: UITapGestureRecognizer and UILongPressGestureRecognizer. Objects of this class should be draggable but only after download. Also when user stop holding object it should go back on its place.

after tap gesture the object should start downloading:

- (void) handleTapGestureRecognizer:(UITapGestureRecognizer*)recognizer
{
   [self loadingFiles:recognizer];
}

Long press gesture is using to drag object but after drop object should go back to its center.

So, I have implemented UIGestureRecognizerDelegate like this:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 
  shouldRecognizeSimultaneouslyWithGestureRecognizer:
  (UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
   if([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]])
   {
     [self loadingFiles:gestureRecognizer];
     return self.isLoaded;
   }
   else return YES;
}

In the UIGestureRecognizerDelegate Protocol Reference there is written that "gestureRecognizerShouldBegin" is available in iOS 3.2 and later but when I use ALT in Xcode there is another information that it is available only in iOS6 and later, why? The method is not called in iOS5. So at the beggining of the handleLongPressGestureRecognizer I wrote:

- (void)handleLongPressGestureRecognizer: (UILongPressGestureRecognizer *)recognizer
{
   if (!self.isLoaded)
  {
     [self loadingFiles:recognizer];
     return;
  }
  else 
 {
     (...)
 }

}

And on iOS6 everything works completely fine, but on iOS5 when I am holding object and try to move it, it's not moving during downloading (it is good) but after this it is changing center and freeze in the last place i kept my finger.

I will appreciate any clues how to solve this problem.

edit: ANSWER

Ok I found an answer for this. Maybe this is not the best solution but it is working: In method "loadingFiles" which is called at the beginning of "handleLongPressGestureRecognizer" method i put:

- (BOOL) loadingFiles:(UIGestureRecognizer*)recognizer
{
   if (!_isSelectable ||! self.isLoaded)
   {
      longPressGestureRecognizer.enabled = NO;
      (...)
   }
}

And where the flag isLoaded is change to YES there is:

longPressGestureRecognizer.enabled = YES;
4

1 に答える 1

0

UIGestureRecognizerDelegate Protocol Referenceには「gestureRecognizerShouldBegin」はiOS 3.2以降で利用可能と書かれていますが、XcodeでALTを使うとiOS6以降でしか利用できないという別の情報があります。

いいえ、あなたは 2 つの異なるものを混同しています。

  • 新しい iOS 6 UIView メソッドがありgestureRecognizerShouldBeginます。これは優先順位を取り、UIView 自身のジェスチャ応答 (UIButton のタップ可能性など) と上位レベルのジェスチャ レコグナイザ (スーパービューに接続されている) との間を仲介します。

  • gestureRecognizerShouldBegin:常に存在するジェスチャ レコグナイザー デリゲート メッセージがあります。

于 2013-05-13T17:52:19.057 に答える