gpt4 book ai didi

ios - 弹出式 UIViewController

转载 作者:IT王子 更新时间:2023-10-29 05:39:06 24 4
gpt4 key购买 nike

我正在尝试制作一个弹出窗口,该弹出窗口将通过按下按钮显示。试图按照我在谷歌中找到的说明进行操作,但我的弹出 View 以全屏显示且其背景为黑色。这是我的代码:

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)
}
}

我做错了什么?

最佳答案

要使您的 View Controller 显示为弹出窗口,您应该设置以下内容:

popupVC.modalPresentationStyle = .overCurrentContext
popupVC.modalTransitionStyle = .crossDissolve

您还应该设计 View Controller 的位置和大小,使其看起来像一个弹出窗口。

这是我之前做的弹出窗口。

enter image description here

关于ios - 弹出式 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37205789/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com