添加滑动手势以显示详细视图中的下一个项目

从集合视图我已经通过细节我想通过细节到详细视图控制器。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { SportsCollectionViewCell *selectedCell = (SportsCollectionViewCell *)sender; SportsBrowserViewController *targetVC = (SportsBrowserViewController *) [segue destinationViewController]; targetVC.targetURL = selectedCell.targetURL; targetVC.sdesc = selectedCell.description.text; targetVC.stitle = selectedCell.title.text; targetVC.simage = selectedCell.image.image; targetVC.scat = selectedCell.category.text; targetVC.sdate = selectedCell.date.text; } 

我想现在向目标视图控制器添加滑动手势,以便我可以到达下一篇文章,而不必返回到主页面。 我已经添加了以下设置手势。

  UISwipeGestureRecognizer *recognizer; recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)]; [recognizer setDirection:UISwipeGestureRecognizerDirectionLeft]; [[self view] addGestureRecognizer:recognizer]; } -(IBAction)swipeHandler:(UISwipeGestureRecognizer *)sender{ NSLog(@"SWIPE"); } 

但是,我不知道如何从这里移动。 有人能指出我正确的方向吗?

我想在这里做的是通过滑动播放一系列图像。

 -(IBAction)swipeHandler:(UISwipeGestureRecognizer *)gesture{ { if(gesture.direction == UISwipeGestureRecognizerDirectionRight) { if ((gesture.state == UIGestureRecognizerStateChanged) || (gesture.state == UIGestureRecognizerStateEnded)) { self.count--; if (self.count<0) { self.count=[yourArticlesArray count]; // for round robin swiping. } CATransition *animation = [CATransition animation]; animation.duration = 0.5; animation.type = kCATransitionMoveIn; animation.subtype = kCATransitionFromLeft; [self loadArticleForIndex:self.count]; [targetVC.layer addAnimation:animation forKey:@"imageTransition"]; } } else { if ((gesture.state == UIGestureRecognizerStateChanged) || (gesture.state == UIGestureRecognizerStateEnded)) { self.count++; if (self.count>=[yourArticleArray count]) { self.count=0; } CATransition *animation = [CATransition animation]; animation.duration = 0.5; animation.type = kCATransitionMoveIn; animation.subtype = kCATransitionFromLeft; [self loadArticleForIndex:self.count]; [targetVC.layer addAnimation:animation forKey:@"imageTransition"]; } } } 

所以我会build议带走我的部分,包括你的文章加载部分,就像我们有计数variables,并猜测你会有你的文章在一个数组或东西你可以写一个这样的方法,

  - (void)loadArticleForIndex:(int)index { //draw ur article or load your webview. if(index>0 && index <[yourArticleArray count]) { //instead of selectedCell take out articles from the array and feed it to your VC properties. self.targetURL = selectedCell.targetURL; self.sdesc = selectedCell.description.text; self.stitle = selectedCell.title.text; self.simage = selectedCell.image.image; self.scat = selectedCell.category.text; self.sdate = selectedCell.date.text; //do something after setting all stuff. } } 

因此,在刷卡期间,准确地计算计数并将计数传递给函数

  [self loadArticleForIndex:count]; 

如果您想要更新下一个项目的细节的视图,在滑动手势处理程序中,您可以使用下一篇文章内容更新视图的内容。 您可以在同一视图中使用animation,以便在幻灯片中生效。

就像是 :

  self.targetURL = newItem.targetURL; self.sdesc = newItem.description.text; self.stitle = newItem.title.text; self.simage = newItem.image.image; self.scat = newItem.category.text; self.sdate = newItem.date.text; 

如果你想能够到下一篇文章,大概是那个之后的文章,那么你应该把整个数组(或者任何你正在填充你的表格)传递给细节控制器,以及所选单元格的indexPath(所以你知道在数组中的哪里获得第一篇文章)。