我正在尝试按下按钮来弹出一个弹出窗口.试图按照我在谷歌中找到的说明,但我的流行视图以全屏显示,其背景为黑色.这是我的代码:
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
@IBAction func someButtonPressed(sender: UIButton) {
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let popupVC = storyboard.instantiateViewControllerWithIdentifier("hello") as! popupViewController
popupVC.modalPresentationStyle = .Popover
popupVC.preferredContentSize = CGSizeMake(300, 300)
let pVC = popupVC.popoverPresentationController
pVC?.permittedArrowDirections = .Any
pVC?.delegate = self
pVC?.sourceView = sender
pVC?.sourceRect = CGRect(x: 100, y: 100, width: 1, height: 1)
presentViewController(popupVC, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
Tie*_*ien 29
要使视图控制器显示为弹出窗口,您应该设置以下内容:
popupVC.modalPresentationStyle = .OverCurrentContext
popupVC.modalTransitionStyle = .CrossDissolve
Run Code Online (Sandbox Code Playgroud)
您还应该设计视图控制器的位置,大小以使其看起来像弹出窗口.
这是我以前做的弹出窗口.
在父控制器上:
let vc = ViewController()
vc.modalPresentationStyle = .overCurrentContext
vc.modalTransitionStyle = .crossDissolve
present(vc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
在弹出控制器上,使用它可以在后台显示父控制器:
self.definesPresentationContext = true
Run Code Online (Sandbox Code Playgroud)
不要忘记为弹出控制器设置半透明背景。
-从参考:-书签交易编程呈现弹出视图控制器 -
归档时间: |
|
查看次数: |
18739 次 |
最近记录: |