diff --git a/Sources/PagerTabStripViewController.swift b/Sources/PagerTabStripViewController.swift index 9aedb7d6..1d27aa70 100644 --- a/Sources/PagerTabStripViewController.swift +++ b/Sources/PagerTabStripViewController.swift @@ -240,15 +240,22 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { for (index, childController) in pagerViewControllers.enumerated() { let pageOffsetForChild = self.pageOffsetForChild(at: index) + if abs(containerView.contentOffset.x - pageOffsetForChild) < containerView.bounds.width { - if childController.parent != nil { - childController.view.frame = CGRect(x: offsetForChild(at: index), y: 0, width: view.bounds.width, height: containerView.bounds.height) - childController.view.autoresizingMask = [.flexibleHeight, .flexibleWidth] + if #available(iOS 11.0, *) { + if case 0 = index { + childController.view.frame = CGRect(x: offsetForChild(at: index), y: 0, width: view.bounds.width - view.safeAreaInsets.right, height: containerView.bounds.height) + } else { + childController.view.frame = CGRect(x: offsetForChild(at: index) + view.safeAreaInsets.left, y: 0, width: view.bounds.width - 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] + + if childController.parent == nil { childController.beginAppearanceTransition(true, animated: false) addChild(childController) - 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(toParent: self) childController.endAppearanceTransition()