Swift PageView导航器按钮设置为新的UIpageview

时间:2015-10-23 22:49:46

标签: swift uipageviewcontroller

我有一个包含4页的综合浏览量。 pageView正在使用之前UIViewController的导航栏。我想在导航栏中设置我的UIPageView按钮以转到新的UIView。问题很少。当我使用performSegueWithIdentifier(“CrankSetViewController”,发件人:发件人)时,它会给我一个黑屏。如何在没有黑屏的情况下以编程方式更改为新的UIView?

1 个答案:

答案 0 :(得分:1)

在Swift中 -

    pageViewController.setViewControllers(startingViewControllers,
        direction: UIPageViewControllerNavigationDirection.Forward,
        animated: true,
        completion: nil)

你可以在@IBAction中设置它

您可以使用setViewControllers:direction:animated:completion:在页面视图控制器上以编程方式使用过渡动画设置当前显示的视图控制器。

这是一个显示具有随机背景颜色的视图控制器的示例。您可以调整此项以使用特定的视图控制器。

- (void)viewDidLoad
{
 [super viewDidLoad];
self.pvc = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pvc.view.frame = CGRectInset(self.view.bounds, 200, 200);
[self.view addSubview:self.pvc.view];

[self.pvc setViewControllers:@[[self randomVC]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}

-(UIViewController*)randomVC
{
UIViewController *vc = [[UIViewController alloc] init];
UIColor *color = [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1];
vc.view.backgroundColor = color;
return vc;
}

- (IBAction)previousButtonPressed:(id)sender {
[self.pvc setViewControllers:@[[self randomVC]] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];
}

- (IBAction)nextButtonPressed:(id)sender {
[self.pvc setViewControllers:@[[self randomVC]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}

希望它能帮到你......