【问题标题】:UISwipeGestureRecognizer for subviews (UIVIew) not working子视图的 UISwipeGestureRecognizer (UIVIew) 不起作用
【发布时间】:2012-09-28 15:44:29
【问题描述】:

我在 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 次,但是当我尝试滑动时它不起作用。

谢谢

【问题讨论】:

    标签: iphone xcode uiview uiswipegesturerecognizer


    【解决方案1】:

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

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

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

    否则hereherehere 这些家伙也遇到了麻烦,也许那里的答案可以帮助你。

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

    祝你好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2020-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多