Skip to content

Commit

Permalink
Merge pull request #233 from sunilprajapati714/master
Browse files Browse the repository at this point in the history
iPhone X Orientation Support
  • Loading branch information
0ber authored Oct 11, 2018
2 parents 91f325c + 0c1e364 commit fd24e7c
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions RAMAnimatedTabBarController/RAMAnimatedTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ open class RAMAnimatedTabBarController: UITabBarController {

var lineLeadingConstraint: NSLayoutConstraint?
var bottomLine: UIView?
var arrBottomAnchor:[NSLayoutConstraint] = []
var arrViews:[UIView] = []

// MARK: life circle

Expand All @@ -274,6 +276,34 @@ open class RAMAnimatedTabBarController: UITabBarController {
}
}

override open func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
coordinator.animate(alongsideTransition: { (transitionCoordinatorContext) -> Void in
let orient = UIApplication.shared.statusBarOrientation

for (index, var layoutAnchor) in self.arrBottomAnchor.enumerated() {

layoutAnchor.isActive = false

switch orient {
case .portrait:
layoutAnchor = self.arrViews[index].bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.topAnchor)
case .landscapeLeft,.landscapeRight :
layoutAnchor = self.arrViews[index].bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.bottomAnchor)
default:
print("Anything But Portrait")
}

self.arrBottomAnchor[index] = layoutAnchor
self.arrBottomAnchor[index].isActive = true
}
self.view.updateConstraints()

}, completion: { (transitionCoordinatorContext) -> Void in
//refresh view once rotation is completed not in will transition as it returns incorrect frame size.Refresh here
})
super.viewWillTransition(to: size, with: coordinator)
}

// MARK: create methods

fileprivate func createCustomIcons(_ containers: [String: UIView]) {
Expand Down Expand Up @@ -436,9 +466,18 @@ open class RAMAnimatedTabBarController: UITabBarController {
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(RAMAnimatedTabBarController.tapHandler(_:)))
tapGesture.numberOfTouchesRequired = 1
viewContainer.addGestureRecognizer(tapGesture)

arrViews.append(viewContainer)

// add constrains
viewContainer.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor).isActive = true
if UIDevice.current.orientation.isLandscape {
let bottomAnchor = viewContainer.bottomAnchor.constraint(equalTo: bottomLayoutGuide.bottomAnchor)
self.arrBottomAnchor.append(bottomAnchor)
bottomAnchor.isActive = true
} else {
let bottomAnchor = viewContainer.bottomAnchor.constraint(equalTo: bottomLayoutGuide.topAnchor)
self.arrBottomAnchor.append(bottomAnchor)
bottomAnchor.isActive = true
}

let constH = NSLayoutConstraint(item: viewContainer,
attribute: NSLayoutConstraint.Attribute.height,
Expand Down

0 comments on commit fd24e7c

Please sign in to comment.