如何更改弹出窗口的大小

如何更改弹出窗口的大小

本文介绍了如何更改弹出窗口的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法更改popover演示文稿的大小。这是我到目前为止

I'm having trouble changing the size of my popover presentation. Here is what I have so far

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

到目前为止,这一切都是以popover为中心并删除箭头,这很好。但它没有调整容器的大小。任何帮助将不胜感激。谢谢。

So far all this does is center the popover and remove the arrow, which is good. but it doesn't resize the container. any help would be greatly appreciated. thank you.

当我使用preferredContentSize时,我收到错误无法分配给属性:'preferredContentSize'是不可变的

when I use preferredContentSize I get the error "Cannot assign to property: 'preferredContentSize' is immutable"

推荐答案

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

Set the preferred content size on the view controller being presented not the 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)

        }
    }

这篇关于如何更改弹出窗口的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 16:19