iOS 12 (and under) orientation rotation

Viewed 63

let's say we have 2 vc, vc1 has the top half of the screen, and vc2 has bottom half in portrait mode, when the device is rotated to the landscape mode, vc1 has to occupy the left half of the screen and vc2 the right one.

all good for ios 13, the transition goes smoothly, but for ios12 and under, vc1 and vc2 overlap at transition...

here is what i've did:

override func viewDidLoad() {
        super.viewDidLoad()

        setOrietation()
    }

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)

        coordinator.animateAlongsideTransition(in: nil, animation:
            {
                [weak self] _ in
                self?.setOrietation()
        }, completion: nil)
    }

    private func setOrietation() {
        if UIScreen.main.bounds.width > UIScreen.main.bounds.height { // landscape

            vc1BottomConstraint.constant = 0
            vc1TrailingConstraint.constant = 450

            vc2TopConstraint.isActive = false
            vc2TopConstraint = vc2.topAnchor.constraint(equalTo: view.topAnchor)
            vc2TopConstraint.isActive = true
            vc2LeftConstraint.isActive = false
            vc2LeftConstraint = vc2.leftAnchor.constraint(equalTo: vc1.rightAnchor)
            vc2LeftConstraint.isActive = true
        } else {
            vc1BottomConstraint.constant = 512
            vc1TrailingConstraint.constant = 0

            vc2TopConstraint.isActive = false
            vc2TopConstraint = vc2.topAnchor.constraint(equalTo: vc1.bottomAnchor)
            vc2TopConstraint.isActive = true
            vc2LeftConstraint.isActive = false
            vc2LeftConstraint = vc2.leftAnchor.constraint(equalTo: view.leftAnchor)
            vc2LeftConstraint.isActive = true
        }
    }

i also tried the same without using constraints and focusing on frame... still the same result

any ideas how i can achieve this ?

0 Answers
Related