Content pushed down in a UIPageViewController with UINavigationController(使用 UINavigationController 在 UIPageViewController 中下推内容)
问题描述
更新 2
我一直在使用 4 英寸设备在 iOS 模拟器中运行和测试我的应用程序.如果我使用 3.5 英寸设备运行,标签不会跳动.在我的 .xib 中,在 Simulated Metrics 下,我将其设置为 Retina 4 英寸全屏.知道为什么我只在 4 英寸设备上看到这个问题吗?
I've been running and testing my app in the iOS Simulator using a 4-inch device. If I run using a 3.5-inch device the label doesn't jump. In my .xib, under Simulated Metrics, I have it set as Retina 4-inch Full Screen. Any idea why I'm only seeing this problem on a 4-inch device?
更新 1
在 IB 中,如果我在 Simulated Metrics 中选择导航栏",我的标签仍然会跳动.我可以让我的标签在第一个屏幕上正确呈现的唯一方法是不将导航控制器设置为我的窗口的根视图控制器.
In IB, if I choose "Navigation Bar" in Simulated Metrics, my label still jumps. The only way I can get my label to render correctly on the first screen is to not set a navigation controller as my window's root view controller.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我的窗口的 rootViewController 被设置为一个 UINavigationController,它的 rootViewController 嵌入了一个 UIPageViewController.
My window's rootViewController is being set to a UINavigationController whose rootViewController has a UIPageViewController embedded.
当我的应用程序加载时,初始视图的内容被向下推了一点,与导航栏的大小大致相同.当我滚动 pageViewController 时,内容会跳转到它放置在 nib 中的位置,并且 pageViewController 加载的所有其他 viewController 都很好.
When my app loads, the initial view is presented with it's content pushed down a bit, roughly the same size as a navigation bar. When I scroll the pageViewController, the content jumps up to where it was placed in the nib, and all other viewControllers loaded by the pageViewController are fine.
在我的 appDelegate 中:
In my appDelegate:
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[ContainerViewController new]];
在 ContainerViewController 中:
In 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];
}
推荐答案
所以我在进一步开发后添加了另一个答案,我终于想知道发生了什么.好像在 iOS7 中,UIPageViewController 有自己的 UIScrollView.因此,您必须将 automaticallyAdjustsScrollViewInsets 设置为 false.这是我的 viewDidLoad 现在:
So I'm adding another answer after further development and I finally think I figured out what's going on. Seems as though in iOS7, UIPageViewController has its own UIScrollView. Because of this, you have to set automaticallyAdjustsScrollViewInsets to false. Here's my viewDidLoad now:
- (void)viewDidLoad
{
[super viewDidLoad];
self.automaticallyAdjustsScrollViewInsets = false;
DetailViewController *detail = [[DetailViewController alloc] init];
[self setViewControllers:@[detail]
direction:UIPageViewControllerNavigationDirectionForward
animated:false
completion:nil];
}
无需在 viewWillLayoutSubviews 中添加任何内容(正如我之前的回答所建议的那样).
No need to put anything in viewWillLayoutSubviews (as one of my previous answers suggested).
这篇关于使用 UINavigationController 在 UIPageViewController 中下推内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 UINavigationController 在 UIPageViewController 中下推内容
基础教程推荐
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
