更新2
我一直使用一个4英寸的设备在iOS模拟器中运行和测试我的应用程序。如果我使用3.5英寸的设备运行,标签不会跳转。在我的.xib中,在模拟指标下,我将其设置为Retina 4英寸全屏。你知道为什么我只在4英寸的设备上看到这个问题吗?
更新1
在IB中,如果我在模拟指标中选择“导航栏”,我的标签仍然跳转。让我的标签在第一个屏幕上正确呈现的唯一方法是不将导航控制器设置为我的窗口的根视图控制器。
我的窗口的rootViewController被设置为一个UINavigationController,它的rootViewController嵌入了一个UIPageViewController。
当我的应用程序加载时,初始视图显示的是它的内容稍微向下推一点,大小与导航栏大致相同。当我滚动pageViewController时,内容会跳到它放在nib中的位置,并且pageViewController加载的所有其他viewControllers都是正常的。
在我的appDelegate中:
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[ContainerViewController new]];
在ContainerViewController中:
- (void)viewDidLoad {
[super viewDidLoad];
self.pvc = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
self.pvc.dataSource = self;
self.pvc.delegate = self;
DetailViewController *detail = [DetailViewController new];
[self.pvc setViewControllers:@[detail]
direction:UIPageViewControllerNavigationDirectionForward
animated:false
completion:nil];
[self addChildViewController:self.pvc];
[self.view addSubview:self.pvc.view];
[self.pvc didMoveToParentViewController:self];
}
发布于 2013-11-15 05:50:28
因此,在进一步开发之后,我添加了另一个答案,我最终认为我弄清楚了是怎么回事。似乎在iOS7中,UIPageViewController有自己的UIScrollView。因此,您必须将automaticallyAdjustsScrollViewInsets
设置为false。下面是我的viewDidLoad
:
- (void)viewDidLoad
{
[super viewDidLoad];
self.automaticallyAdjustsScrollViewInsets = false;
DetailViewController *detail = [[DetailViewController alloc] init];
[self setViewControllers:@[detail]
direction:UIPageViewControllerNavigationDirectionForward
animated:false
completion:nil];
}
不需要在viewWillLayoutSubviews
中放任何东西(正如我之前的答案之一所建议的那样)。
发布于 2014-11-18 04:19:17
这肯定是由automaticallyAdjustsScrollViewInsets
引起的,就像其他帖子(包括@djibuti33)一样。然而,这个属性在两个方面很奇怪:
UINavigationController
上设置。如果你在一个由UINavigationController
管理的子控制器上设置它,它不会有任何效果。仅当滚动视图在控制器的子视图中的索引为零时,1这两个警告应该可以解释线程中的其他人遇到的间歇性问题。
TLDR:我使用的一个解决方法是在索引为0的UIPageViewController
中添加一个虚拟视图,以避免将该设置应用于页面控制器中的scrollView,如下所示:
pageViewController.view.insertSubview(UIView(), atIndex: 0) // swift
[pageViewController.view insertSubview: [UIView new] atIndex: 0]; // obj-c
更好的方法是自己在滚动视图上设置contentInset
,但不幸的是UIPageViewController
不会显示滚动视图。
发布于 2015-08-04 06:41:25
只需取消选中Under Top Bars
:UIPageViewController
和您的自定义PageContentViewController
https://stackoverflow.com/questions/18202475
复制相似问题