Screen Orientation Changing

I'm experiecing some chaos here. I try to adjust my UIView as necessray when the phone orientation changes. I used this code:



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

        self.drawingViewTablet.clear()
        self.buttonsShowing.clear()
      
            coordinator.animate(alongsideTransition:nil) { (UIViewControllerTransitionCoordinatorContext) in
                self.drawingViewTablet.adjust(TransitionTo: size, NewPoints:  self.farPoints)
                self.buttonsShowing.adjust(TransitionTo: size, NewPoints: self.farPoints)
        }
      
    }

When my adjust() functions are being called, the UIView they refer to are *not* always done rotating. How can I only call these adjust functions when my entire ViewController is 100% rotating ???

Replies

Doc states that super.viewWillTransition must be called.

If you override this method in your custom view controllers, always call super at some point in your implementation so that UIKit can forward the size change message appropriately. View controllers forward the size change message to their views and child view controllers. Presentation controllers forward the size change to their presented view controller.


So, call

        super.viewWillTransition(to: size, with: coordinator)

This still doesn't fix my issue.



Now I'm trying:


    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        self.zoneGoView.clear()
        self.buttonsShowing.clear()
      
        coordinator.notifyWhenInteractionChanges { context in
            if !context.isCancelled {
                self.zoneGoView.adjust(TransitionTo: size, NewPoints: self.farPoints)
                self.buttonsShowing.adjust(TransitionTo: size, NewPoints: self.farPoints)
             
            }
        }
    }


and line 8 and 9 are not being called at al..

For my undertsanding: why did you change

from

coordinator.animate(alongsideTransition

to

coordinator.notifyWhenInteractionChanges


Did you test with coordinator.animate(alongsideTransition:)after adding call to super ?


It seems that context isCancelled each time you call coordinator.notifyWhenInteractionChanges.

What happens if you remove the test if !context.isCancelled ?

I switched it becasue of an incositency, the UIView zoneGoView or buttonsShowing isn't *always* done transitioning when I use animate. If I take that off - the code still doesn't get called. What's the best way to call a function *after* my view is done transitioning?

You could call the function in


func viewDidLayoutSubviews()