我无法更改popover演示文稿的大小.以下是我到目前为止的情况

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) // func for popover
{
    if segue.identifier == "popoverView"
    {
        let vc = segue.destinationViewController

        let controller = vc.popoverPresentationController

        if controller != nil
        {
            controller?.delegate = self
            controller?.sourceView = self.view
            controller?.sourceRect = CGRect(x:CGRectGetMidX(self.view.bounds), y: CGRectGetMidY(self.view.bounds),width: 315,height: 230)
            controller?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)
        }
    }
}

到目前为止,所有这一切都是中心的爆米花和删除箭头,这是好的.但它不会调整容器的大小.任何帮助都将不胜感激.非常感谢.

当我使用preferredContentSize时,会出现错误"无法分配给属性:'preferredContentSize'是不可变的"

推荐答案

在显示的视图控制器上设置首选内容大小,而不是popoverPresentationController

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) // func for popover
    {
        if segue.identifier == "popoverView"
        {
            let vc = segue.destinationViewController

            vc.preferredContentSize = CGSize(width: 200, height: 300)

            let controller = vc.popoverPresentationController

            controller?.delegate = self
            //you could set the following in your storyboard
            controller?.sourceView = self.view
            controller?.sourceRect = CGRect(x:CGRectGetMidX(self.view.bounds), y: CGRectGetMidY(self.view.bounds),width: 315,height: 230)
            controller?.permittedArrowDirections = UIPopoverArrowDirection(rawValue: 0)

        }
    }

Swift相关问答推荐

try 在SwiftUI中做5星评级

更改正在进行的异步任务的完成(SWIFT并发)(&q;)?

如何通过 Enum 属性使用新的 #Predicate 宏获取

VisionOS TabBar预览中是否存在漏洞?

为什么 id 不能通过 struct 从 Objective-C 移植到 Swift?

如何从另一个 swift 文件中调用函数

为什么 SwiftUI 不在工具栏菜单中反映 @State 属性值?

如何更改任务栏 colored颜色 和 sf 符号 colored颜色 ?

如何处理永远不会失败的 String.Encoding 初始化程序?

不要从 NumberFormatter 获取货币符号

如何使被拖动的对象成为前景(foreground)对象

使用 swift 运行 pod install 时出错

Swift 动画 WithDuration 语法是什么?

如何为多个类 Swift 进行扩展

两个 Date 对象之间的所有日期 (Swift)

在 Swift 中覆盖 UIScrollView 的委托属性(就像 UICollectionView 一样)

swift中静态函数和单例类的区别

SwiftUI:将多个 BindableObjects 放入环境

如何将 Int 拆分为其各个数字?

iPhone 纵向和 iPad 横向的通用应用程序