gpt4 book ai didi

ios - 无法在 Swift 3.0 中将 View Controller 显示为弹出 Controller

转载 作者:行者123 更新时间:2023-11-28 15:41:25 25 4
gpt4 key购买 nike

我正在尝试将我的 View Controller 添加为弹出 Controller 。但是每次我使用代码时, View 都会从底部滑动,而不是像我希望的那样。下面是我正在使用的代码

    let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let popupVC = storyboard.instantiateViewController(withIdentifier: "WSFilterViewController") as! WSFilterViewController
popupVC.modalPresentationStyle = UIModalPresentationStyle .popover
popupVC.preferredContentSize = CGSize (width: 300, height:300)
let pVC = popupVC.popoverPresentationController
pVC?.permittedArrowDirections = UIPopoverArrowDirection.any
pVC?.delegate = self as? UIPopoverPresentationControllerDelegate
self.present(popupVC, animated: true, completion: nil)

我想要如图所示

enter image description here

我们将不胜感激。

提前致谢

最佳答案

let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let popupVC = storyboard.instantiateViewController(withIdentifier: "WSFilterViewController")
popupVC.modalPresentationStyle = UIModalPresentationStyle .popover
popupVC.preferredContentSize = CGSize(width: 170, height: 130)
popupVC.popoverPresentationController?.delegate = self
popupVC.popoverPresentationController?.sourceView = sender as? UIView // button
popupVC.popoverPresentationController?.sourceRect = (sender as AnyObject).bounds
self.present(popupVC, animated: true, completion: nil)

问题有所不同,现在已经解决了。

谢谢大家

关于ios - 无法在 Swift 3.0 中将 View Controller 显示为弹出 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43651684/

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