儿童视图控制器降档 [英] Child View Controller shifts down

查看:127
本文介绍了儿童视图控制器降档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有PageViewController一个TutorialsViewController加入编程为:

I have a TutorialsViewController that has a PageViewController added programmatically as:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    // Create page view controller
    self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"TutorialsPageViewController"];
    self.pageViewController.dataSource = self;

    TutorialsContentViewController *startingViewController = [self viewControllerAtIndex:0];

    NSArray *viewControllers = @[startingViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];

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

和我使用的委托方法添加TutorialsContentViewController到PageViewController:

And I add TutorialsContentViewController to the PageViewController using the delegate methods:

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
    NSUInteger index = ((TutorialsContentViewController*) viewController).pageIndex;

    if ((index == 0) || (index == NSNotFound)) {
        return nil;
    }

    index--;
    return [self viewControllerAtIndex:index];
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
    NSUInteger index = ((TutorialsContentViewController*) viewController).pageIndex;

    if (index == NSNotFound) {
        return nil;
    }

    index++;
    if (index == [self.tutorialsArray count]) {
        return nil;
    }
    return [self viewControllerAtIndex:index];
}

- (TutorialsContentViewController *)viewControllerAtIndex:(NSUInteger)index {
    if (([self.tutorialsArray count] == 0) || (index >= [self.tutorialsArray count])) {
        return nil;
    }

    // Create a new view controller and pass suitable data.
    TutorialsContentViewController *tutorialsContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"TutorialsContentViewController"];
    tutorialsContentViewController.imageName = [self.tutorialsArray objectAtIndex:index];
    tutorialsContentViewController.pageIndex = index;
    return tutorialsContentViewController;
}

现在,当我在模拟器中运行这个,我所看到的一切工作正常,只是下一子视图控制器似乎是在状态栏上方,当我滚动它向下移动。

Now when i run this in simulator, i can see everything working fine, just that the next child view controller appears to be above the status bar and it shifts down as I scroll.

我已经试过self.automaticallyAdjustsScrollViewInsets =父视图控制器,但孩子仍然认为向下移动假的。子视图控制器已前置,设置为0开始的顶部,底部约束的ImageView的(这使得换​​档)。

I have tried self.automaticallyAdjustsScrollViewInsets = false in the Parent View Controller but the child view still shifts down. The child view controller has an ImageView that has leading, trailing, top, bottom constraints set to 0 initially (this causes the shift).

当我水平和垂直居中的形象,并给它固定的高度和宽度,它工作正常不过。但我想要的图像完全填充子视图控制器。

When i centre the image horizontally and vertically and give it fixed height and width, it works fine though. But i want the image to completely fill the child view controller.

如何解决这个观点转变的问题?请帮助。

How to solve this view shifting problem? Please help.

感谢。

推荐答案

我似乎已经找到了它的修复,这是关系到我已经建立了自动布局约束。我的孩子视图控制器包含完全填充它的成像图。所以我给下面的约束到图像视图:

I seem to have found the fix for it, it was related to the auto layout constraints i had set up. My child view controller contains an image view that completely fills it. So i give following constraints to the image view:


  1. 水平居中容器

  2. 垂直居中容器

  3. 相等的宽度(到容器视图)

  4. 的高度相等(到容器视图)

这将停止切换视图/闪烁的问题。

This stops the view shifting/flickering problem.

这篇关于儿童视图控制器降档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆