UIPageViewController中的顶部栏

时间:2013-08-16 08:32:01

标签: ios uipageviewcontroller

我的应用程序基于Xcode中的默认“基于页面的应用程序”。我试图在我的故事板中的DataViewController顶部显示一个导航栏,而不使用导航控制器。问题是,当我向左和向右滑动时,导航栏似乎与手势一起。我怎么能让它“不可动”?

我尝试的事情:

  • 将导航栏放在我的RootViewController中。当我模拟应用程序时,导航栏不可见。

编辑: RootViewController.m

- (void)viewDidLoad{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Configure the page view controller and add it as a child view controller.
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.delegate = self;

GJDataViewController *startingViewController = [self.modelController viewControllerAtIndex:0 storyboard:self.storyboard];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];

self.pageViewController.dataSource = self.modelController;

[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];

// Set the page view controller's bounds using an inset rect so that self's view is visible around the edges of the pages.
CGRect pageViewRect = self.view.bounds;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    pageViewRect = CGRectInset(pageViewRect, 40.0, 40.0);
}
self.pageViewController.view.frame = pageViewRect;

[self.pageViewController didMoveToParentViewController:self];

// Add the page view controller's gesture recognizers to the book view controller's view so that the gestures are started more easily.
self.view.gestureRecognizers = self.pageViewController.gestureRecognizers;
}

DataViewController.m

- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.dataLabel.text = [self.dataObject description];
}

1 个答案:

答案 0 :(得分:0)

请按照以下步骤操作:

  1. 使用您的第二次试用:“将导航栏放在我的RootViewController中。”使每个年龄转换的导航栏都不可移动。
  2. 现在在RootViewController.m中,将行CGRect pageViewRect = self.view.bounds;更改为CGRect pageViewRect = CGRectMake(self.view.bounds.origin.x, 64, self.view.bounds.size.width, self.view.bounds.size.height-64);。其中64 = 20(状态栏高度)+ 44(导航栏)高度。
  3. 第二步将调整您的DataViewController视图的框架,在RootViewController中添加了导航栏,因此导航栏不会隐藏。

    希望,它可以帮助你......快乐的编码! : - )