Gesture recognition device stopped working in iOS 4.3

My gesture recognition code worked fine in iOS 4.2, but it doesn't work in iOS 4.3. I can’t find any registered changes in gesture recognizers from iOS 4.2 to 4.3, but I confirmed on both the iPad and the simulator that my code no longer works.

This is what I do:

In my opinion, the controller’s ViewDidLoad method, I set:

UISwipeGestureRecognizer *swipeUpGesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedScreenLeft:)] autorelease];
swipeUpGesture.numberOfTouchesRequired = 2;
swipeUpGesture.direction = (UISwipeGestureRecognizerDirectionLeft);
[scrollView addGestureRecognizer:swipeUpGesture];

In iOS 4.2, this works as expected, but in iOS 4.3, swipedScreenLeft never gets called, even when I sit down with two fingers. Everything compiles and runs without errors and warnings.

Is there anything that could prevent this gesture recognizer from working in iOS 4.3, even if it works fine in iOS 4.2?

I also noticed that under iOS 4.2, if I touched the screen with two fingers, but didn’t make the right gesture, nothing would happen, but in iOS 4.3, if I touch the screen with two fingers, it acts as if I were just touching one with your finger. It is as if iOS 4.3 is not recognizing multi-touch events in my application.

Another note: my tapGestureRecognizer works fine in iOS 4.3, it's just a swipeGestureRecognizer that doesn't.

+3
source share
3 answers

The problem is only in UIScrollView, I was also angry at this: http://i.stack.imgur.com/dqx3d.png

[UPDATE 1] Here's the solution:

Situation: The UIViewController view has a UIScrollView as a preview (scroll view disabled).

, , UIView:

UISwipeGestureRecognizer *swipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedScreenLeft:)];
[swipeLeftRecognizer setNumberOfTouchesRequired:2.0f];
swipeLeftRecognizer.delegate = self;
[swipeLeftRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];

[self.view addGestureRecognizer:swipeLeftRecognizer];

[swipeLeftRecognizer release];

iOS 4.3, UIViewController UIGestureRecognizerDelegate

scrollView panGesture . :

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

    if ([gestureRecognizer isKindOfClass:[UISwipeGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
        return YES;
    }

    return NO;

}

[ 2]

UIScrollView , , scrollview, UISCrollView panGesture, . , / scrollView scroll functionlity UISwipeGestureRecognizer. , , .

.

@property (nonatomic,assign) UISwipeGestureRecognizer *swipeRightRecognizer;
@property (nonatomic,assign) UISwipeGestureRecognizer *swipeLeftRecognizer;

:

[self setSwipeRightRecognizer:[[UISwipeGestureRecognizer alloc] initWithTarget:nil action:nil]];
[swipeRightRecognizer setNumberOfTouchesRequired:2.0f];
swipeRightRecognizer.delegate = self;
[swipeRightRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[self addObserver:self forKeyPath:@"swipeRightRecognizer.state" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL];
[self.view addGestureRecognizer:swipeRightRecognizer];
[swipeRightRecognizer release];

[self setSwipeLeftRecognizer:[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedScreenLeft:)]];
[swipeLeftRecognizer setNumberOfTouchesRequired:2.0f];
swipeLeftRecognizer.delegate = self;
[swipeLeftRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
[self addObserver:self forKeyPath:@"swipeLeftRecognizer.state" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL];
[self.view addGestureRecognizer:swipeLeftRecognizer];
[swipeLeftRecognizer release];

:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {

    if (self.swipeRightRecognizer.state == UIGestureRecognizerStateFailed) {
        self.scrollView.scrollEnabled = YES;
        return;
    }

    if ([self.swipeRightRecognizer numberOfTouches] != 2.0f) {
        self.scrollView.scrollEnabled = YES;   
    }
    else{
        self.scrollView.scrollEnabled = NO;   
    }
}

, "[UPDATE]":

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{

    if ([gestureRecognizer isKindOfClass:[UISwipeGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
        if ([gestureRecognizer numberOfTouches] != 2.0f) {
            self.scrollView.scrollEnabled = YES;   
        }
        else{
            self.scrollView.scrollEnabled = NO;   
        }

        return YES;
    }
    return NO;
}

, dealloc:

[self removeObserver:self forKeyPath:@"swipeRightRecognizer.state"];
[self removeObserver:self forKeyPath:@"swipeLeftRecognizer.state"];

, , .

, ;)

+8

UIImageView , User Interaction. , .

+1

Perhaps my code will help you in solving your problem. I tested the code on an iPad with iOS 4.3 and it works great

UISwipeGestureRecognizer *oSwipeLeft = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(mPreviousPage:) ] autorelease];
oSwipeLeft.numberOfTouchesRequired = 2;
oSwipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:oSwipeLeft];

UISwipeGestureRecognizer *oSwipeRight = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(mNextPage:) ] autorelease];
oSwipeRight.numberOfTouchesRequired = 2;
oSwipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:oSwipeRight];

UISwipeGestureRecognizer *oSwipeUp = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(mPreviousPage:) ] autorelease];
oSwipeUp.numberOfTouchesRequired = 2;
oSwipeUp.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:oSwipeUp];
0
source

All Articles