2016-07-25 73 views
1

彈出模式在橫向模式下顯示時會佔用整個屏幕,但縱向模式下它仍能正常工作。另外,當我在橫向模式下點擊彈出窗口外時,它不會消失。swift - 在橫向模式下彈出不能正確顯示

我通過故事板連接了popover。在popoverviewcontroller裏面,我放置了一個包含按鈕的視圖。在viewDidLoad中()的popoverviewcontroller的代碼是:

override func viewDidLoad() { 
    super.viewDidLoad() 

    self.preferredContentSize = popoverView.frame.size 
     } 

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

肖像:

enter image description here

景觀:

enter image description here

回答

2

您必須添加UIPopoverPresentationControllerDelegate到您的類象這個:

SWIFT 3

import UIKit 

class ViewController: UIViewController, UIPopoverPresentationControllerDelegate { 
    ... 

第二步,添加以下功能:

func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle { 
    return UIModalPresentationStyle.none 
} 

說明:通過返回UIModalPresentationStyle無,在初始呈現風格保持與你的酥料餅是沒有橫向拉伸到屏幕的底部。

相關問題