stefanceriu / SCPageViewController

Just like UIPageViewController but better.. :)
MIT License
352 stars 70 forks source link

Can't set initial page #8

Closed markst closed 8 years ago

markst commented 9 years ago

It seems that setting the content inset of the scroll view rests the content offset. https://github.com/stefanceriu/SCPageViewController/blob/master/SCPageViewController/SCPageViewController.m#L547

I'm also unable to set the initial page that's loaded before viewDidLoad calls on reloadData which loads the first page.

markst commented 9 years ago

After loading the view I can set the page with navigateToPageAtIndex: which works until viewWillLayoutSubviews triggers resetting of the content insets (after viewWillAppear:) the above commit resolves this issue for me.

stefanceriu commented 9 years ago

I'm trying to reproduce this viewWillLayoutSubviews problem and getting nowhere. I'm setting the page and then changing the pageViewController's frame so that it triggers a re-layout. I added this to the RootViewController from the Demo project:

- (void)viewWillAppear:(BOOL)animated
{
[self.pageViewController navigateToPageAtIndex:20 animated:NO completion:nil];
[self.pageViewController.view setFrame:CGRectInset(self.view.bounds, 10, 10)];
}

Everything seems to be where I expect it to be so is there anything else that you're doing differently ?

As for setting the page before the view controller is loaded, you really shouldn't do that. Firstly because the scrollView isn't instantiated yet so there's nothing to set a contentOffset on and secondly because these page calculations rely on the pageViewController's bounds which won't necessarily be correct at that point. Any reason why you can't delay this current page setting until everything is set up properly ?

markst commented 9 years ago

this is still an issue for me.

vikmeup commented 9 years ago

@stefanceriu it's still happening.

Only possible to set initial page on viewDidAppear, and it's too late.

stefanceriu commented 9 years ago

This last commit should address the problem. Have a look and let me know, if it's all good I'll push it to master and release a new version.

vikmeup commented 9 years ago

I found a way around it by setting a layout:

self.setLayouter(SCPageLayouter(), andFocusOnIndex: index, animated: false) { () -> Void in

}

Thanks. I will check out develop branch.