Swip the scrollview,the containerView.contentOffset.y keeps -20.0.But Tap the button to show otherview, containerView.contentOffset.y changed to 0.0,It seems as statusbar'height.How to solve it?
I had this problem too but I had a navigation bar, so it was being offset by 64 (statusBarHeight + navBarHeight). I traced the problem back to moveToViewControllerAtIndex(index:, animated:) where the contentOffset was being set. Instead of using 0 for the yOrigin in the 3 setContentOffset calls, use -64.
containerView.setContentOffset(CGPointMake(pageOffsetForChildIndex(index: index), -64), animated: animated)
I had this problem too, it bothering me for a long time。 I use three UINavigationController as a UITabBarController tabBar, one of the UINavigationController‘s rootViewController is a subclass of ButtonBarPagerTabStripViewController,and like the example I add this in viewDidLoad:
self.buttonBarView.removeFromSuperview()
self.navigationController?.navigationBar.addSubview(self.buttonBarView)
but,the containerView offsetY is diff when Swip the view and Tap the button,
I fix this by two step :
one add this before super.viewDidLoad():
self.containerView.frame = self.view.frame
and override moveToViewControllerAtIndex , and not use super.moveToViewControllerAtIndex
override func moveToViewControllerAtIndex(index: Int, animated: Bool){
// super.moveToViewControllerAtIndex(index)
self.containerView.setContentOffset(CGPointMake(pageOffsetForChildIndex(index: index), -64), animated: animated)
}
But,why? Is there some things wrong?
I have this issue also, when trying to use TLYShyNavBar to house the tab bar view. It works fine when the view controller loads, and when swiping horizontally across views. It breaks when tapping a tab, for the same issue mentioned above.
I believe a fix that _should_ work for the more general case is to simply change:
self.containerView.setContentOffset(CGPointMake(pageOffsetForChildIndex(index: index), 0), animated: animated)
To:
self.containerView.setContentOffset(CGPointMake(pageOffsetForChildIndex(index: index), self.containerView.contentOffset.y), animated: animated)
If XLPagerTabStrip uses the existing contentOffset (rather than changing it), things seem to work. And I can't think of any negative side effects here. But I haven't tested all cases.
I find the final solution, if you use XLPagerTabStrip under UINavigationController , this code is important in viewDidLoad
edgesForExtendedLayout = UIRectEdge.None
@cougarwww Thanks.I tried it as you said,but do not works
This is causing me some issues too. Any ideas on how to fix it for good? I'm trying to display a collection view controller, so getting the offsets correct for both controllers is proving a problem.
@359796875 Can you provide a git repository as sample code , I try to be able to solve, maybe your situation is not the same with me.
@cougarwww Force it to -20.0 , hope it works for you
public var scrollPercentage: CGFloat {
// print("containerView:(containerView.contentOffset)")
if swipeDirection != .Right {
containerView.contentOffset.y = -20.0
let module = fmod(containerView.contentOffset.x, pageWidth)
return module == 0.0 ? 1.0 : module / pageWidth
}
I find the final solution, if you use XLPagerTabStrip under UINavigationController , this code is important in viewDidLoad
edgesForExtendedLayout = UIRectEdge()
Thanks to @cougarwww
@yissan Thanks
Most helpful comment
I find the final solution, if you use XLPagerTabStrip under UINavigationController , this code is important in viewDidLoad
edgesForExtendedLayout = UIRectEdge.None