简体   繁体   中英

Horizontal scroll infinite view

I am creating a news app. The requirement is that.

  1. A list to display news. User can pull to get latest news list.
  2. When user select one news, it will navigate to the detail view.
  3. In the detail view. user can slide finger to navigate to next or previous news.

For the requirement 1,2. There is a lot of solutions out there. it's easy. But for the requirement3. I think it's a little difficult. Assuming we have a list of 10 news. I select the second news to get to its detail view. If I slide my finger from left to right, It will navigate to the first news view. When I slide from left to right again. It should access the service to see if there is latest news available. If yes, then it should navigate the latest news.

I would like to know if there is any third party project is doing this logic? Any comments is appreciated!

I dun think there is any logic that specific.. You will have to create the logic yourself.

For Requirement 1 and 2, you could use this to list the latest news -> RevealViewController

For Requirement 3, you need to add gesturerecognizer like swipeleft and swiperight.

This is a just an example:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tappedRightButton:)];
    [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
    [self.view addGestureRecognizer:swipeLeft];

    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(tappedLeftButton:)];
    [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
    [self.view addGestureRecognizer:swipeRight];
}

- (IBAction)tappedRightButton:(id)sender
{
    NSUInteger selectedIndex = [rootVC.tabBarController selectedIndex];

    [rootVC.tabBarController setSelectedIndex:selectedIndex + 1];
} 

- (IBAction)tappedLeftButton:(id)sender
{
    NSUInteger selectedIndex = [rootVC.tabBarController selectedIndex];

    [rootVC.tabBarController setSelectedIndex:selectedIndex - 1]; 
}

Just modify the logic for tappedRightButton and tappedLeftButton accordingly..Hope this helps..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM