Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPageViewController subviews move behind the status bar after screen tap

So, I have a segue from UICollecionView item tapped to UIPageViewController. When PageViewController shows, the navigation bar makes dark gray, and UIView in it has a strange offset. However, after i click once in any place on screen, I see a strange "animation" and UIView moves up into its correct place. So, all views on screen get moved.

Here is the link for 5-second video with this bug: http://www.youtube.com/watch?v=CNbwBGvSzIk

PageViewController.m:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = [[[EVAEvent events] objectAtIndex:self.currentIndex] name];
    self.dataSource = self;
    self.delegate = self;
    UIViewController *vc = [self viewControllerAtIndex:self.currentIndex];
    NSArray *controllers = [NSArray arrayWithObjects:vc, nil];
    [self setViewControllers:controllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}

- (UIViewController *)viewControllerAtIndex:(NSUInteger)index;
{
//    NSLog(@"View Controller At Index = %lu", (unsigned long)self.currentIndex);
    EVAEventInfoViewController *controller = [EVAEventInfoViewController getFromStoryboard];
    EVAEvent *event = [[EVAEvent events] objectAtIndex:index];
    [controller setIndex:index];
    [controller setEvent:event];
    return controller;
}

EVAEventInfoViewController.m:

+ (EVAEventInfoViewController *) getFromStoryboard
{
    //NSLog(@"Creating EVAEventInfoViewController");
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
    EVAEventInfoViewController *this = (EVAEventInfoViewController *)[sb instantiateViewControllerWithIdentifier:@"eventInfoController"];
    return this;
}

Thanks a lot!

like image 756
Egor Avatar asked Dec 19 '13 13:12

Egor


2 Answers

try adding

self.automaticallyAdjustsScrollViewInsets=NO;

in PageViewController's viewDidLoad

like image 122
Rainelz Avatar answered Nov 14 '22 09:11

Rainelz


I set UIPageViewController and sub view controller with self.automaticallyAdjustsScrollViewInsets=NO; but it does not work if UITabBarController as root.

I captured the view hierarchy as the following enter image description here enter image description here

You can see the UIPageViewControllerContentView are correct position (0,0). But UIView under _UIQueuingScrollView generated the offset of status bar.

So, I decided not to use UIPageViewController. I use self.view addSubView to fixed this issue.

- (void)loadVC:(UIViewController*)vc
{
    [self addChildViewController:vc];
    vc.view.frame = self.view.bounds;
    [self.view addSubview:vc.view];
}
like image 27
Yang Young Avatar answered Nov 14 '22 09:11

Yang Young