1

从集合视图中,我通过 segue 将我想要的详细信息传递给了详细视图控制器。

    - (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");

}

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

4

3 回答 3

1

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

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

        }
    }
  }

所以我的建议是去掉我的部分并包括你的文章加载部分,比如我们有 count 变量并猜测你会将你的文章放在一个数组中,或者你可以编写这样的方法,

  - (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];
于 2013-08-27T05:34:41.340 回答
0

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

就像是 :

  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;
于 2013-08-27T05:33:36.100 回答
0

如果您希望能够转到下一篇文章,并且大概是在那之后的文章,等等,那么您应该将整个数组(或您在表格中填充的任何内容)传递给细节控制器以及所选单元格的 indexPath(因此您知道在数组中的哪个位置获取第一篇文章)。

于 2013-08-27T05:40:02.100 回答