Xcode iOS5滑动手势切换图像-请求帮助

Xcode iOS5滑动手势切换图像-请求帮助,xcode,uiview,uiimageview,uigesturerecognizer,Xcode,Uiview,Uiimageview,Uigesturerecognizer,我有很多图片,我想用手势来回推。我知道PageViewController非常适合这样做,但我不知道如何在使用NIBs的现有项目中使用它 所以。我正在尝试构建UIView动画。我可以看到第一张图片,但手势不起作用 如蒙帮助,我将不胜感激 以下是两个例程之一的代码,以及手势初始化: - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

我有很多图片,我想用手势来回推。我知道PageViewController非常适合这样做,但我不知道如何在使用NIBs的现有项目中使用它

所以。我正在尝试构建UIView动画。我可以看到第一张图片,但手势不起作用

如蒙帮助,我将不胜感激

以下是两个例程之一的代码,以及手势初始化:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    NSLog(@"%s", __FUNCTION__);
    return YES;
}


- (void)handleSwipe:(UISwipeGestureRecognizer *)recognizer {

     NSLog(@"%s", __FUNCTION__);
     switch (recognizer.direction)
     {
          case (UISwipeGestureRecognizerDirectionRight):
               [self performSelector:@selector(previousPage:)];
               //[self previousPage];
               break;               

          case (UISwipeGestureRecognizerDirectionLeft): 
               [self performSelector:@selector(nextPage:)];
               //[self nextPage];
               break;

          default:
               break;
     }     
}     



- (void)nextPage {
     [UIView beginAnimations:@"fadeOut" context:nil];
     [UIView setAnimationDelay:0.0f];
     [UIView setAnimationDuration:0.5f];
     [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
     pageNumber ++;
     if(pageNumber > maxInfoPages)
     {
          pageNumber = 1;
     }
     NSString *imageName = [NSString stringWithFormat:@"infoPage%i.png", pageNumber];
     imageView.image = [UIImage imageNamed:imageName];     
     NSLog(@"imageName is: %@", imageName);                                    
     NSLog(@"imageView is: %@", imageView);
     imageView.clipsToBounds=YES;     
     self.view = imageView;
     [UIView commitAnimations];
}

非常感谢

如果您没有实际设置UIgestureRecognitors并将其添加到视图中,您将不会收到任何发送到viewController的事件。因此,您需要将UIGestureRecognizers附加到将拦截刷卡的视图。例如,在viewDidLoad方法中,您可以按照以下方式执行操作:

UISwipeGestureRecognizer *rightSwipe=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
rightSwipe.direction=UISwipeGestureRecognizerDirectionRight;

UISwipeGestureRecognizer *leftSwipe=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
leftSwipe.direction=UISwipeGestureRecognizerDirectionLeft;

[self.view addGestureRecognizer:leftSwipe];
[self.view addGestureRecognizer:rightSwipe];

// leave out the following if using ARC
[leftSwipe release];
[rightSwipe release];

祝你好运

我最终将原来的代码换成了PageViewController代码。其中的示例来自Erica Sadun的新书:iOS5开发者食谱。。这本书将于11月14日出版,但预购者可以购买。

您是否将手势识别器连接到相关视图?谢谢。是的,我更新了上面的代码。蒂姆,谢谢,但是他在那里。事实上,我让手势起作用了,但是页面是空白的。我已经得到了显示图像的页面。至少在日志文件中,但现在手势已经停止。。我将检查手势是否链接到此视图。他们可能在应用程序代理中。。。