2016-07-11 64 views
0

我在Xcode中使用模板Page-Based ApplicationRootViewControllerDataViewController,ModelController)。我想在时间间隔后翻页。我该怎么做?如何在时间间隔后翻页?

代码翻转翻页

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

回答

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

哪个控制器我必须使用它的代码? – user214155

+0

你可以使用这个代码在你想要翻转的控制器上。 –

+0

例如:控制器A是您当前的类,然后添加此代码的某些操作,然后代码将翻转到另一个控制器B –

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 
    }]; 
}); 
+0

请看屏幕 https: //drive.google.com/file/d/0B0EJbcHq3ZALRVQxbGhfcHVpeDg/view?usp=sharing – user214155

+0

我worte“在你的代码中定义fromViewController”。我几乎没有改变我的答案。 – Igor

+0

您必须将此片段调整为您的代码。我不知道代码中的控制器名称。 – Igor