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"];
, , .
, ;)