2017-04-27 41 views
0

我試圖將我的視圖控制器添加爲彈出控制器。但是,每當我使用代碼時,視圖會從底部滑動,而不是像我希望的那樣。下面是我使用無法在Swift 3.0中將視圖控制器顯示爲彈出控制器

let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
    let popupVC = storyboard.instantiateViewController(withIdentifier: "WSFilterViewController") as! WSFilterViewController 
    popupVC.modalPresentationStyle = UIModalPresentationStyle .popover 
    popupVC.preferredContentSize = CGSize (width: 300, height:300) 
    let pVC = popupVC.popoverPresentationController 
    pVC?.permittedArrowDirections = UIPopoverArrowDirection.any 
    pVC?.delegate = self as? UIPopoverPresentationControllerDelegate 
    self.present(popupVC, animated: true, completion: nil) 

顯示

enter image description here

任何幫助可以理解的代碼,我想它的形象。

在此先感謝

+0

如文檔所述:在橫向緊湊環境中,此選項的行爲與fullScreen相同。 – Kubba

+0

你是在iPad或iPhone設備上? –

+0

你缺少源碼查看,sourceRect和委託 –

回答

0
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
    let popupVC = storyboard.instantiateViewController(withIdentifier: "WSFilterViewController") 
    popupVC.modalPresentationStyle = UIModalPresentationStyle .popover 
    popupVC.preferredContentSize = CGSize(width: 170, height: 130) 
    popupVC.popoverPresentationController?.delegate = self 
    popupVC.popoverPresentationController?.sourceView = sender as? UIView // button 
    popupVC.popoverPresentationController?.sourceRect = (sender as AnyObject).bounds 
    self.present(popupVC, animated: true, completion: nil) 

的問題是不同的東西,現在想通了。

謝謝大家

+0

它仍然採取整個屏幕@gurmandeep –

相關問題