Constraints don't work when changing view orientation

How to enforce placement restrictions for correct position representation

My app only supports portrait orientation, but one view manager should always open in landscape mode. I managed to change the orientation a lot and work correctly.

But my view restrictions do not work as expected when navigating to this view for the first time, or moving after changing device orientation. Once it is loaded and the orientation change does not happen, its preview will load as expected. The limitations do not ensure that the subview is displayed correctly in an orientation when the device is already in that orientation. I am working in xcode 8.2.1.

I checked many links but couldn't find a solution for this problem. I've also tried updating the view and constraints.

    self.view.setNeedsUpdateConstraints()
    self.view.setNeedsLayout()
    self.view.setNeedsDisplay()
    self.view.setNeedsFocusUpdate()

      

The code I am using is -

    override func viewDidLoad()
    {
        super.viewDidLoad()
      let value = UIInterfaceOrientation.landscapeLeft.rawValue
        UIDevice.current.setValue(value, forKey: "orientation")
    }

    override func viewWillDisappear(_ animated: Bool)
    {
       let value = UIInterfaceOrientation.portrait.rawValue
        UIDevice.current.setValue(value, forKey: "orientation")
    }

    override var shouldAutorotate: Bool
    {
        return true
    }

      

The view is loaded like this when my device is already in landscape mode and I go to that view controller and force it to landscape mode. It has been updated to landscape mode but does not update the restrictions.

When tapped and repeated, select the option it shows how it should be in landscape mode.

+3


source to share





All Articles