Update constraints on changing the window size of application in Split Mode Screen

553 Views Asked by At

I have an application which works fine in iPhone and iPad. But when the app is running in split mode I want to update the constraints for the view whenever we change the split mode window size from 1/3,2/3 and so on. How we can know that the app is working on these screens and update constraints accordingly. In the case of split mode changing the view is not updating with the constraints.

I have used below code to recognise the orientation change and update constraints successfully and its working fine.

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

          if UIDevice.current.orientation.isLandscape {
              containerWidthConstraintForLandscape = NSLayoutConstraint(item: containerView, attribute: .width, relatedBy: .equal, toItem: view, attribute: .width, multiplier: 0.5, constant: 0)
              NSLayoutConstraint.activate([containerWidthConstraintForLandscape])
              NSLayoutConstraint.deactivate([containerWidthConstraintForPortrait])
           }
          else {
             containerWidthConstraintForPortrait = NSLayoutConstraint(item: containerView, attribute: .width, relatedBy: .equal, toItem: view, attribute: .width, multiplier: 0.7, constant: 0)
             NSLayoutConstraint.deactivate([containerWidthConstraintForLandscape])
             NSLayoutConstraint.activate([containerWidthConstraintForPortrait])
          }

    }

It would be great if someone could tell me how i can update these constraints while changing the window size in Split Mode/ Slide Over in iPad. Thanks in Advance

0

There are 0 best solutions below