【发布时间】:2016-04-05 06:33:44
【问题描述】:
通常我遵循此处的说明:https://stackoverflow.com/a/24687152/3741933。
但是,正如其 cmets 中所讨论的,无论preferredContentSize 或sourceRect 是什么,弹出框始终是全屏的。
显示弹出框的按钮:
func buttonClicked(sender: UIButton!) {
let ac = EmptyViewController() as UIViewController
ac.modalPresentationStyle = .Popover
ac.preferredContentSize = CGSizeMake(200, 200)
let popover = ac.popoverPresentationController
popover?.delegate = self
popover?.permittedArrowDirections = .Any
popover?.sourceView = self.view
popover?.sourceRect = CGRect(x: 100, y: 100, width: 100, height: 100)
presentViewController(ac, animated: true, completion: nil)
}
UIViewController:
import UIKit
class EmptyViewController : UIViewController {
override func viewDidLoad() {
view.backgroundColor = UIColor.redColor()
}
}
我想知道如何使它成为一个真正的弹出框(不是全屏尺寸)。顺便说一句,正如@EI Captain 所说,它在 iPad 上完美运行,但在 iPhone 上总是全屏。
【问题讨论】:
-
在 iPhone 中具有纵向模式,此代码弹出框始终全屏显示...在 iPad 中完美运行...仍然检查此richardallen.me/2014/11/28/popovers.html
-
@EICaptain 你说得对,它在 iPad 上完美运行。但是本教程正在使用 IB。我想知道如何使它以编程方式工作。
-
可能您需要为此制作自定义视图或使用任何库
-
可能对你有帮助...github.com/corin8823/Popover
标签: ios swift uiviewcontroller popover