繁体   English   中英

子视图的UISwipeGestureRecognizer(UIVIew)无法正常工作

[英]UISwipeGestureRecognizer for subviews (UIVIew) not working

我在self.view内部有3个子视图的View Controller。 我正在尝试在它们之间滑动,但是它不起作用。 这是我的代码:

- (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次,但是当我尝试滑动时却无法正常工作。

谢谢

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

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

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

否则,这些人在这里这里这里也会遇到一些麻烦,也许那里的答案可以帮助您。

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

祝好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM