我在 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)
最佳答案
弹出窗口的大小不受 PopoverPresentationController
控制。 PopoverPresentationController
仅指定如何呈现内容,但内容本身(包括大小)由您从中获取 Controller 的 View 设置,在您的示例中为 myAlert
。
您尝试设置 preferredContentSize
的想法是正确的,但是您在错误的 View 上设置了它。你应该换行
popoverPresentationController?.preferredContentSize = /* ... */
到:
myAlert.preferredContentSize = /* ... */
这应该可以解决问题。
关于ios - 如何修改或更改 PopoverPresentationController 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42978871/