添加滑动手势以显示详细视图中的下一个项目 [英] Add Swipe Gesture to display the next Item in the Detailed View

查看:118
本文介绍了添加滑动手势以显示详细视图中的下一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从集合视图我已经通过segue将详细信息传递给详细视图控制器。

From the Collection View I have passed the details I want via segue to the Detailed View Controller.

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


 }

我现在要添加滑动手势到目标视图控制器,这样我就可以进入下一篇文章而无需返回主页面。我添加了以下内容来设置手势。

I want to now add a swipe gesture to the destination view controller so that I can get to the next article without having to go back to the main page. I have added the following to set up the gesture.

     UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeHandler:)];
[recognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:recognizer];
}

-(IBAction)swipeHandler:(UISwipeGestureRecognizer *)sender{
NSLog(@"SWIPE");

}

但是,我不知道如何离开这里。有人能指出我正确的方向。

However, I do not know how to move from here. Could someone point me in the right direction.

推荐答案

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

What I am trying to do here is play a sequence of images, by swiping.

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

        }
    }
  }

那是什么我建议删除我的部分,并加载你的部分文章,比如说我们有计数变量并猜测你会把你的文章放在一个数组中,或者你可以写一个这样的方法,

SO what I would suggest is take away my part and include the article loading part of yours, say like we have the count variable and guessing that you would have your articles in a array or something you could write a method like this,

  - (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.
        }
  }

因此,在滑动期间准确计算计数并传递计数功能如

So during swipes calculate the count accurately and pass the count to the function like

   [self loadArticleForIndex:count];

这篇关于添加滑动手势以显示详细视图中的下一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆