如何在时间间隔后翻页?

时间:2016-07-11 10:50:55

标签: ios objective-c uipageviewcontroller

我在Xcode中使用模板Page-Based ApplicationRootViewControllerDataViewControllerModelController)。我希望在时间间隔后翻页。我该怎么做?

翻页下一页的代码

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

2 个答案:

答案 0 :(得分:0)

我希望这会对你有所帮助

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
                            }];

[或]

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
            }];

答案 1 :(得分:0)

要在时间间隔后翻转,请使用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
    }];
});