Xlpagertabstrip: iPhoneX safe area problem.

Created on 7 Dec 2017  路  10Comments  路  Source: xmartlabs/XLPagerTabStrip

There is a problem with the 'safe area' in landscape mode on iPhoneX.

Xcode 9.2(9C40b)
iOS 11.2
XLPagerTabStrip : 2017.12.06 download

1

Most helpful comment

Solved!!!

ON PagerTabStripViewController 242 to 254 replace the code with this IF block

if let _ = childController.parent {
if #available(iOS 11.0, *) {
childController.view.frame = CGRect(x: offsetForChild(at: index) + view.safeAreaInsets.left, y: 0, width: view.bounds.width - (view.safeAreaInsets.left + view.safeAreaInsets.right), height: containerView.bounds.height)
} else {
childController.view.frame = CGRect(x: offsetForChild(at: index), y: 0, width: view.bounds.width, height: containerView.bounds.height)
}
childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
}
else {
childController.beginAppearanceTransition(true, animated: false)
addChildViewController(childController)
if #available(iOS 11.0, *) {
childController.view.frame = CGRect(x: offsetForChild(at: index) + view.safeAreaInsets.left, y: 0, width: view.bounds.width - (view.safeAreaInsets.left + view.safeAreaInsets.right), height: containerView.bounds.height)
} else {
childController.view.frame = CGRect(x: offsetForChild(at: index), y: 0, width: view.bounds.width, height: containerView.bounds.height)
}
childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
containerView.addSubview(childController.view)
childController.didMove(toParentViewController: self)
childController.endAppearanceTransition()
}

All 10 comments

Seeing the same problem on a project using the library. Safe Area seems to be ignored when in Landscape.

Yes, this is a real issue. It seems like the cached size of the view is retained and not recalculated upon rotation on a device that respects safe are guides.

You can fix it by calling :

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        coordinator.animate(alongsideTransition: { (_) in

        }, completion: { _ in
            self.reloadPagerTabStripView()
        })

        super.viewWillTransition(to: size, with: coordinator)
    }

in parent container View Controller

Same problem here, version 8.0.1

Solved!!!

ON PagerTabStripViewController 242 to 254 replace the code with this IF block

if let _ = childController.parent {
if #available(iOS 11.0, *) {
childController.view.frame = CGRect(x: offsetForChild(at: index) + view.safeAreaInsets.left, y: 0, width: view.bounds.width - (view.safeAreaInsets.left + view.safeAreaInsets.right), height: containerView.bounds.height)
} else {
childController.view.frame = CGRect(x: offsetForChild(at: index), y: 0, width: view.bounds.width, height: containerView.bounds.height)
}
childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
}
else {
childController.beginAppearanceTransition(true, animated: false)
addChildViewController(childController)
if #available(iOS 11.0, *) {
childController.view.frame = CGRect(x: offsetForChild(at: index) + view.safeAreaInsets.left, y: 0, width: view.bounds.width - (view.safeAreaInsets.left + view.safeAreaInsets.right), height: containerView.bounds.height)
} else {
childController.view.frame = CGRect(x: offsetForChild(at: index), y: 0, width: view.bounds.width, height: containerView.bounds.height)
}
childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth]
containerView.addSubview(childController.view)
childController.didMove(toParentViewController: self)
childController.endAppearanceTransition()
}

This is just an example problem. Safe area should be handled in each child (content) view controller (otherwise child view controller can't fill the background of entire screen). So

childController.view.frame = CGRect(x: offsetForChild(at: index) + view.safeAreaInsets.left, y: 0, width: view.bounds.width - (view.safeAreaInsets.left + view.safeAreaInsets.right), height: containerView.bounds.height)

this is not correct.

We can fix the example by updating PostCell (to use UITableViewCell.insetsContentViewsToSafeArea). I'll address it.

Submitted #612.

Why this still doesn't work for me ? The incorrect solution from DanielBalsalobre looks like works fine so I will use that probably. Maybe because I don't use storyboards , just using lib programmatically, maybe that is not addressed in this issue ??

Or somethinng like this...

override open func updateContent() {
        super.updateContent()
        for (index, childController) in controllers.enumerated() {
            childController.view.frame = CGRect(x: offsetForChild(at: index) + view.safeAreaInsets.left,
                    y: 0, width: view.bounds.width - (view.safeAreaInsets.left + view.safeAreaInsets.right),
                    height: containerView.bounds.height)
        }
    }

My solution (based on rene-dohan's answer):

override open func updateContent() {
  super.updateContent()
  if viewControllers.count > currentIndex {
    viewControllers[currentIndex].view.setNeedsUpdateConstraints()
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

niuguoning picture niuguoning  路  14Comments

bdrelling picture bdrelling  路  14Comments

royatv picture royatv  路  10Comments

359796875 picture 359796875  路  10Comments

hrsalehi picture hrsalehi  路  20Comments