0

我使用 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;
}

数据视图控制器.m

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

1 回答 1

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);.Where 64=20(status-bar height) + 44(navigation-bar) height。

第二步将在 RootViewController 中添加导航栏下方调整 DataViewController 视图的框架,因此导航栏不会隐藏。

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

于 2014-07-10T09:41:57.177 回答