当表加载在滑动视图上时,给表的上下滑动添加手势
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
[swipe setDirection:UISwipeGestureRecognizerDirectionDown];
swipe.delegate = self;
[cell addGestureRecognizer:swipe];
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
[swipeUp setDirection:UISwipeGestureRecognizerDirectionUp];
swipeUp.delegate = self;
[cell addGestureRecognizer:swipeUp];
-(void)swipe:(UISwipeGestureRecognizer*)swipe
{
if (swipe.direction == UISwipeGestureRecognizerDirectionUp) {
NSLog(@"上");
}
else{
NSLog(@"下");
}
}
//需要添加解决的冲突
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
if ([otherGestureRecognizer.view isKindOfClass:[UIScrollView class]]) {
return YES;
}
return NO;
}
网友评论