iOS: How to run a function after Device has Rotated (Swift)

后端 未结 3 1214
傲寒
傲寒 2020-12-02 16:52

I have one UIView which is not using Auto-Layout and some components are displayed based on their percent of X and Y co-ordinates from the main view.

Previously I wo

3条回答
  •  孤城傲影
    2020-12-02 16:53

    The viewWillTransitionToSize delegate method gets called with a UIViewControllerTransitionCoordinator conforming object. A method that protocol declares is animateAlongsideTransition(_:animation, completion:). You can use that to have code execute after the transition is complete.

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
        coordinator.animate(alongsideTransition: nil) { _ in
            // Your code here
        }
    }
    

提交回复
热议问题