2016-12-29 73 views
1
func displayPopover() { 

    let popController = UIViewController() 
    popController.view.backgroundColor = .red 

    // set up the popover presentation controller 
    popController.modalPresentationStyle = .popover 
    popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up 
    popController.popoverPresentationController?.delegate = self 
    popController.popoverPresentationController?.sourceView = self.view 
    popController.popoverPresentationController?.sourceRect = CGRect(x: 100, y: 100, width: 100, height: 100) 

    // present the popover 
    self.present(popController, animated: true, completion: nil) 
} 

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController!) -> UIModalPresentationStyle { 
    // Return no adaptive presentation style, use default presentation behaviour 
    return .none 
} 

它顯示與任何其他視圖控制器一樣的彈出窗口,從底部滑動顯示紅色屏幕。無法呈現popover控制器

+0

你的iPhone或iPad檢查呢?我想你正在檢查iPhone – 2016-12-29 10:06:38

回答

0

按照文檔

在一個水平定期的環境,其中內容顯示在酥料餅的視圖表現風格。背景內容變暗,在彈出窗口之外點擊導致彈出窗口被解除。如果您不想點擊關閉彈出窗口,則可以將一個或多個視圖分配給關聯的UIPopoverPresentationController對象的passthroughViews屬性,您可以從popoverPresentationController屬性中獲取該對象。 在橫向緊湊環境中,此選項的行爲與fullScreen相同。

對於iPhone popOver的行爲將與全屏相同,對於iPad,它將顯示在彈出視圖中。

1

獲得 「彈出」 效果:

1.You應的viewController在故事板,然後裏面添加視圖像這樣的(也添加約束):

enter image description here

2.You應申報酥料餅是這樣的:

let popOverVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("popupID") as! PopUpViewController 
self.addChildViewController(popOverVC) 
popOverVC.view.frame = self.view.frame 
self.view.addSubview(popOverVC.view) 
popOverVC.didMoveToParentViewController(self) 

3.Now你應該做背景暗,透明這樣self.view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.8)viewDidLoad()

4.And打開它(它也蓬勃生機略):

self.view.transform = CGAffineTransformMakeScale(1.3, 1.3) 
     self.view.alpha = 0.0; 
     UIView.animateWithDuration(0.25, animations: { 
      self.view.alpha = 1.0 
      self.view.transform = CGAffineTransformMakeScale(1.0, 1.0) 
     });