ios - 如何修改或更改 PopoverPresentationController 的大小?

标签 ios swift popover

我在 iOS Swift 上使用了 popoverPresentationController 并且我在 popover 中同时放置了图像和文本?

我遇到的问题是内容对于弹出框来说太大了?是否可以设置尺寸?

我遇到的问题以及试用代码和错误消息的图片都在下面吗?

  let myAlert = UIAlertController(title: "\n\n\n\n\n\n", message: "Correct answer selected, move on to next level", preferredStyle: UIAlertControllerStyle.actionSheet)

    let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default)
    {
        //  action in self.dismiss(animated: true, completion: nil)

        action in self.performSegue(withIdentifier: "goSegue1", sender: self)

        self.musicEffect.stop()
    }
    // put image into action sheet
    let imageView = UIImageView(frame: CGRect(x: 70, y: -30, width: 140, height: 140))
    imageView.image = #imageLiteral(resourceName: "wellDone2.png")

    myAlert.addAction(okAction);
    myAlert.view.addSubview(imageView)

    // display the alert messgae

    myAlert.popoverPresentationController?.sourceView = view
    myAlert.popoverPresentationController?.sourceRect = (sender as AnyObject).frame
    myAlert.preferredContentSize = CGSize(width: 500, height: 800)

Issue

最佳答案

弹出窗口的大小不受 PopoverPresentationController 控制。 PopoverPresentationController 仅指定如何呈现内容,但内容本身(包括大小)由您从中获取 Controller 的 View 设置,在您的示例中为 myAlert

您尝试设置 preferredContentSize 的想法是正确的,但是您在错误的 View 上设置了它。你应该换行

popoverPresentationController?.preferredContentSize = /* ... */

到:

myAlert.preferredContentSize = /* ... */

这应该可以解决问题。

关于ios - 如何修改或更改 PopoverPresentationController 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42978871/

相关文章:

iOS 9 : Different push tokens returned for the same app (between installes)

ios - Xcode 中的导航 Controller

iphone - 如何通过iphone app中的代码获取用户的当前位置?

swift - 带有自定义对象的 setObjectForKey 方法在 NSUserDefaults swift 中不起作用

ios - 使用 `.receive(on: DispatchQueue.main)` 时未接收到输入

ios - Swift 注释 Pin 的 Calloutbubble 手势

swift - popoverController 没有 seguing

javascript - 使用 Twitter 的 Bootstrap 时,如何更改弹出窗口的内容?

ios - xcode项目中我的数据库文件在哪里

jquery - 如果与 Prototype JS 一起使用,Popover 会隐藏父元素