2016-07-11 63 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