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;