Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift - Popover is not displayed correctly in landscape mode

Tags:

ios

swift

popover

Popover takes the complete screen when displayed in landscape mode, it works correctly in portrait mode though. Also, it is does not disappear when i click outside the popover in landscape mode.

I connected the popover through the storyboard. Inside the popoverviewcontroller I placed a view which contains the buttons. The code for the viewdidload() of the popoverviewcontroller is:

override func viewDidLoad() {
    super.viewDidLoad()

    self.preferredContentSize = popoverView.frame.size
        }

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

Portrait:

enter image description here

landscape:

enter image description here

like image 677
Saad Rehman Avatar asked Jul 25 '16 16:07

Saad Rehman


1 Answers

The answer from @Jake2Finn works for Swift 4.0.

The trait parameter specifically is required to fix the landscape problem:

traitCollection: UITraitCollection

Without it the function adaptive... only works for portrait.

like image 132
Markv07 Avatar answered Sep 28 '22 01:09

Markv07