Swift - How to detect orientation changes

后端 未结 13 1767
余生分开走
余生分开走 2020-11-29 19:49

I want to add two images to single image view (i.e for landscape one image and for portrait another image)but i don\'t know how to detect orientation changes using swift lan

相关标签:
13条回答
  • 2020-11-29 20:56

    Swift 4+: I was using this for soft keyboard design, and for some reason the UIDevice.current.orientation.isLandscape method kept telling me it was Portrait, so here's what I used instead:

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
        super.viewWillTransition(to: size, with: coordinator)
    
        if(size.width > self.view.frame.size.width){
            //Landscape
        }
        else{
            //Portrait
        }
    }
    
    0 讨论(0)
提交回复
热议问题