2012-09-28 32 views
0

我在self.view中有一個包含3個子視圖的View Controller。 我試圖在它們之間滑動,它不工作。 這裏是我的代碼:用於子視圖(UIVIew)不工作的UISwipeGestureRecognizer

- (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]; 
     } 
    } 

我真的看到「裝載2」正在打印的3倍,但是當我試圖滑動它不工作。

謝謝

回答

0

你在這裏使用UIScrollView?這可能是問題所在。

我想你可以使用標準的UIScrollView的委託方法在這種情況下:

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

否則這些傢伙hereherehere遇到了一些麻煩太多,也許答案有可能幫助你。

如果你在這裏沒有使用UIScrollView?我應該使用一個,爲什麼不呢? 3 Subviews和刷到下一個聽起來就像一個不錯的UIScrollView示例(使用分頁)。

祝你好運!