0

I use template Page-Based Application(RootViewController, DataViewController, ModelController) in Xcode. I want to flip page after time interval. How can I do it?

Code for flip next page

    - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    NSUInteger index = [self indexOfViewController:(DataViewController *)viewController];
    if (index == NSNotFound) {
        return nil;
    }

    index++;
    if (index == [self.pageData count]) {
        return nil;
    }
    return [self viewControllerAtIndex:index storyboard:viewController.storyboard];
}
user214155
  • 111
  • 1
  • 1
  • 8

2 Answers2

0

i hope this will help you

HomeViewController *homeVC = [[HomeViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:homeVC];
[UIView transitionFromView:self.view toView:nav.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
                                    //Action to Implement
                            }];

[or]

HomeViewController *homeVC = [[HomeViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:homeVC];
nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[[self navigationController] presentViewController:nav animated:YES completion:^{
               //Action to implement
            }];
0

To flip after time interval use dispatch_after.

// define fromViewController depend on your previous code
UIViewController *toViewController = [self pageViewController:pageViewController viewControllerAfterViewController:viewController];
// or set another toViewController depend on your previous  code

NSTimeInterval interval = 5; //in seconds
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(interval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    [UIView transitionFromView:fromViewController.view toViewController:toViewController.view duration:0.4 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
        //completion block
    }];
});
Igor
  • 12,165
  • 4
  • 57
  • 73