0

我在 self.view 中有一个带有 3 个子视图的视图控制器。我试图在它们之间滑动,但它不起作用。这是我的代码:

- (void)viewDidLoad
{    
    UISwipeGestureRecognizer *swipeGestureRecognizerLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
    swipeGestureRecognizerLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    for (UIView *subview in self.view.subviews) 
    {       
        if([subview isKindOfClass:[UIView class]] && !([subview isKindOfClass:[UIImageView class]]))
        {  
             [subview addGestureRecognizer:swipeGestureRecognizerLeft];
             NSLog(@"Load 2");    
        }
    }
}

    -(void) didSwipe:(UISwipeGestureRecognizer *) swipeRecognizer {
        NSLog(@"Load swipe");

        if (swipeRecognizer.direction==UISwipeGestureRecognizerDirectionLeft) 
        {
            NSLog(@"swipe Left"); 
            [self SlideToLeft];
        }
    }

我真的看到“Load 2”被打印了 3 次,但是当我尝试滑动时它不起作用。

谢谢

4

1 回答 1

0

你在这里使用 UIScrollView 吗?这可能是问题所在。

我认为您可以在这种情况下使用标准的 UIScrollView 委托方法:

- (void) scrollViewDidScroll: (UIScrollView *) sender
{
    NSLog(@"Scrolled!");
}

否则这里这里这里的这些人也有一些麻烦,也许那里的答案可以帮助你。

如果您在这里不使用 UIScrollView?我应该用一个,为什么不呢?3 个子视图和滑动到下一个听起来就像一个不错的 UIScrollView 示例(使用分页)。

祝你好运!

于 2012-10-23T15:23:39.813 回答