2017-03-23 55 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,我試過了你的建議,但它仍然沒有改變警報的整體尺寸? –