我試圖修改我的彈窗寬度,這是一個UITableViewController
,因此它只佔用父視圖寬度的一半。當點擊另一個UITableView
(父視圖)中的按鈕時,彈出窗口以編程方式調用。我嘗試設置popover的preferredContentSize
並設置sourceRect
,但popover仍佔據整個屏幕。修改Popover視圖控制器的寬度
class MyTableViewController: UITableViewController, UICollectionViewDataSource, UICollectionViewDelegate, UIDynamicAnimatorDelegate, UIGestureRecognizerDelegate, CLLocationManagerDelegate, UIPopoverPresentationControllerDelegate, UIAdaptivePresentationControllerDelegate {
...
func goToPlaces(button: UIButton) {
let fromRect = CGRectMake(50.0, 50.0, self.view.bounds.width/2.0, self.view.bounds.height)
let popoverVC = storyboard?.instantiateViewControllerWithIdentifier("otherPlaces")
popoverVC?.modalPresentationStyle = .OverFullScreen
presentViewController(popoverVC!, animated: true, completion: nil)
popoverVC?.view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.6)
popoverVC?.preferredContentSize = CGSizeMake(self.view.bounds.width/2.0, self.view.bounds.height)
let popoverController = popoverVC?.popoverPresentationController
popoverPresentationController?.sourceView = self.view
popoverPresentationController?.sourceRect = fromRect
popoverController?.permittedArrowDirections = .Any
popoverController?.delegate = self
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return .None
}
編輯: 當我做的 popoverPresentationController?.sourceView
和 popoverPresentationController?.sourceRect
他們都返回零打印出於某種原因
不應該將當前聲明作爲最後一個嗎?配置完所有內容後? –
@Rage我在創建這個問題之前就試過了,它沒有什麼區別。非常奇怪的行爲說至少 – wxcoder