Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用UINavigationController在UIPageViewController中下推的内容_Ios_Objective C_Xcode_Uinavigationcontroller_Uipageviewcontroller - Fatal编程技术网

Ios 使用UINavigationController在UIPageViewController中下推的内容

Ios 使用UINavigationController在UIPageViewController中下推的内容,ios,objective-c,xcode,uinavigationcontroller,uipageviewcontroller,Ios,Objective C,Xcode,Uinavigationcontroller,Uipageviewcontroller,更新2 我一直在用4英寸的设备在iOS模拟器上运行和测试我的应用程序。如果我使用3.5英寸的设备跑步,标签不会跳转。在我的.xib中,在模拟指标下,我将其设置为视网膜4英寸全屏。知道我为什么只在4英寸设备上看到这个问题吗 更新1 在IB中,如果我在模拟度量中选择“导航栏”,我的标签仍然会跳转。在第一个屏幕上正确渲染标签的唯一方法是不要将导航控制器设置为窗口的根视图控制器 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 我的窗口的rootViewController被

更新2

我一直在用4英寸的设备在iOS模拟器上运行和测试我的应用程序。如果我使用3.5英寸的设备跑步,标签不会跳转。在我的.xib中,在模拟指标下,我将其设置为视网膜4英寸全屏。知道我为什么只在4英寸设备上看到这个问题吗

更新1

在IB中,如果我在模拟度量中选择“导航栏”,我的标签仍然会跳转。在第一个屏幕上正确渲染标签的唯一方法是不要将导航控制器设置为窗口的根视图控制器

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

我的窗口的rootViewController被设置为UINavigationController,其rootViewController嵌入了UIPageViewController

当我的应用程序加载时,初始视图显示的内容向下推一点,大小与导航栏大致相同。当我滚动pageViewController时,内容跳到nib中的位置,pageViewController加载的所有其他ViewController都正常

在我的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];
}

最初,我的视图控制器层次结构如下所示:

-- UINavigationController
  -- MyContainerViewController
    -- UIPageViewController
      -- MyDetailViewController
-- UINavigationController
  -- MyPageViewController
    -- MyDetailViewController
pageViewController.view.insertSubview(UIView(), atIndex: 0) // swift

[pageViewController.view insertSubview: [UIView new] atIndex: 0]; // obj-c
我这样设置它,以便MyContainerViewController可以管理工具栏。我把问题缩小到MyContainerViewController,然后我想到,如果我将UIPageViewController子类化,我甚至不需要它。现在,我的层次结构如下所示:

-- UINavigationController
  -- MyContainerViewController
    -- UIPageViewController
      -- MyDetailViewController
-- UINavigationController
  -- MyPageViewController
    -- MyDetailViewController
pageViewController.view.insertSubview(UIView(), atIndex: 0) // swift

[pageViewController.view insertSubview: [UIView new] atIndex: 0]; // obj-c

MyPageViewController
管理它的
工具栏
,在4英寸和3.5英寸的设备上,一切正常。

我最初的答案暂时解决了这个问题,但过了一会儿,同样的问题又来了

使用以下viewController层次结构:

-- UINavigationController
  -- MyPageViewController
    -- MyDetailViewController
下面是我为解决这个问题所做的:

在MyPageViewController.m中

@interface MyPageViewController () <delegates>
  @property (strong) MyDetailViewController *initialViewController;
@end

- (void)viewDidLoad
{
    ...

    // set this once, because we're going to use it in viewWillLayoutSubviews,
    // which gets called multiple times
    self.initialViewController = [MyDetailViewController new];
}

// the problem seemed to stem from the fact that a pageViewController couldn't
// properly lay out it's child view controller initially if it contained a 
// scroll view. by the time we're in layoutSubviews, pageViewController seems to
// have gotten it's bearings and everything is laid out just fine.
- (void)viewWillLayoutSubviews
{
    [self setViewControllers:@[self.initialViewController]
                   direction:UIPageViewControllerNavigationDirectionForward
                    animated:false
                  completion:nil];
}
@接口MyPageViewController()
@属性(强)MyDetailViewController*initialViewController;
@结束
-(无效)viewDidLoad
{
...
//设置一次,因为我们将在ViewWillLayoutSubView中使用它,
//它被多次调用
self.initialViewController=[MyDetailViewController新建];
}
//问题似乎源于pageViewController无法
//如果子视图控制器包含
//滚动查看。当我们进入layoutSubviews时,pageViewController似乎
//已经确定了方向,一切都安排得很好。
-(无效)视图将布局子视图
{
[self-SetViewController:@[self.initialViewController]
方向:UIPageViewControllerNavigationDirectionForward
动画:错误
完成:无];
}

因此,在进一步开发之后,我添加了另一个答案,我最终认为我找到了答案。似乎在iOS7中,UIPageViewController有自己的UIScrollView。因此,必须将
自动调整滚动视图insets
设置为false。下面是我的
viewDidLoad
现在:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.automaticallyAdjustsScrollViewInsets = false;

    DetailViewController *detail = [[DetailViewController alloc] init];
    [self setViewControllers:@[detail]
                   direction:UIPageViewControllerNavigationDirectionForward
                    animated:false
                  completion:nil];
}

无需在
视图WillLayoutSubviews
(正如我之前的一个答案所建议的那样)中放入任何内容。

这肯定是由
自动调整滚动视图插图造成的,就像其他海报(包括@djibouti33)一样。但是,此属性在两个方面很奇怪:

  • 它必须在
    UINavigationController
    上设置。如果将其设置在由
    UINavigationController
    管理的子控制器上,则不会产生任何效果
  • 仅当滚动视图在控制器子视图中的索引为零时,此选项才适用 这两个警告应该解释线程中其他人遇到的间歇性问题

    TLDR:我使用的一种解决方法是在索引0处向
    UIPageViewController
    添加一个虚拟视图,以避免设置应用于页面控制器内的滚动视图,如下所示:

    -- UINavigationController
      -- MyContainerViewController
        -- UIPageViewController
          -- MyDetailViewController
    
    -- UINavigationController
      -- MyPageViewController
        -- MyDetailViewController
    
    pageViewController.view.insertSubview(UIView(), atIndex: 0) // swift
    
    [pageViewController.view insertSubview: [UIView new] atIndex: 0]; // obj-c
    

    最好是自己在滚动视图上设置
    contentInset
    ,但不幸的是
    UIPageViewController
    没有显示滚动视图。

    如“Bo”所述::put self.edgesForExtendedLayout=UIRectEdgeNone;在viewDidLoad中,MyPageViewController解决了问题我也有同样的问题。我通过在UIPageViewController的viewDidLoad中放置第一页的SetViewController来解决这个问题,而不是在创建UIPageViewController实例时设置它。另外,我需要将automaticallyAdjustsScrollViewInsets设置为NO.

    这是我第一次发布关于堆栈溢出的帖子,但我已经为这个问题寻找解决方案一周多了

    这是我提出的一个解决方案,我希望这对其他有同样问题的人有效

    我不确定如何为详图视图控制器初始化框架,但我假设您可能使用:self.view.frame.size.height

    尝试使用: self.view.frame.size.height-=self.navigationController.navigationBar.bounds.size.height


    希望这有帮助

    我也遇到过类似的问题,但这里的解决方案都不起作用。我的问题是,每当我滚动到下一页时,内容都会向下跳转,以正确的位置结束,但开始的像素太高(显然与状态栏有关)。我的容器VC不是nav VC。在把我的头发拔出来一段时间后,最终对我有效的解决方案就是确保我的内容VC中没有任何约束连接到顶部布局指南。这在你的情况下可能可行,也可能不可行,但在我的情况下是可行的,这是解决内容跳跃的唯一办法。同样非常奇怪的是,这个问题只有在转换样式设置为滚动时才会出现。只需将其更改为page curl,问题就消失了。但我需要卷轴。希望这对其他人有帮助。

    尝试选择PageVie
    addChildViewController(pageMenu!) 
    self.view.addSubview(pageMenu!.view) 
    pageMenu!.didMove(toParentViewController: self)
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.automaticallyAdjustsScrollViewInsets = false
    }