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
}
它像任何其他视图控制器一样显示弹出窗口,从底部滑动显示红色屏幕。
答案 0 :(得分:1)
获得“弹出”效果:
1.您应该在storyboard中创建viewController,然后在其中添加视图(也添加约束):
2.你应该像这样声明弹出窗口:
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.现在你应该像self.view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.8)
viewDidLoad()
一样使背景更暗更透明
4.打开它(它也会略微激活它):
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)
});
答案 1 :(得分:0)
根据文件
在水平常规环境中,一种呈现样式,其中内容以弹出视图显示。背景内容变暗,弹出窗口外的水龙头导致弹出窗口被解除。如果您不想使用tap来关闭popover,可以将一个或多个视图分配给关联的UIPopoverPresentationController对象的passthroughViews属性,您可以从popoverPresentationController属性获取该属性。 在水平紧凑的环境中,此选项与fullScreen的行为相同。
对于iPhone popOver
的行为与全屏相同,对于iPad,它将以弹出视图显示。