2017-03-23 56 views
-1

我在iOS Swift上使用了popoverPresentationController,并且我已经在popover中放置了图像和文本?如何修改或更改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

+0

请编辑您的问题,并将您的实际代码复制并粘贴到问题中。不要发布代码图片。 – rmaddy

回答

1

的酥料饼的尺寸不被PopoverPresentationController控制。 PopoverPresentationController仅指定如何呈现内容,但内容本身(包括大小)由您从中获得控制器的视图设置,在您的案例中为myAlert

您有正确的想法试图设置preferredContentSize,但您将其设置在错误的视图上。你应该改变行

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

到:

myAlert.preferredContentSize = /* ... */ 

这应该解决的问题。

+0

感谢Pedro,我试过了你的建议,但它仍然没有改变警报的整体尺寸? –