2015-09-26 28 views
0

我試圖修改我的彈窗寬度,這是一個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?.sourceViewpopoverPresentationController?.sourceRect

他們都返回零打印出於某種原因

+0

不應該將當前聲明作爲最後一個嗎?配置完所有內容後? –

+0

@Rage我在創建這個問題之前就試過了,它沒有什麼區別。非常奇怪的行爲說至少 – wxcoder

回答

0

您所要求的

popoverVC?.modalPresentationStyle = .OverFullScreen 

所以你得到它覆蓋整個屏幕。嘗試使用:

popoverVC?.modalPresentationStyle = .Popover 

presentViewController(popoverVC!, animated: true, completion: nil) 

也應該是最後一次,這樣的委託可以得到其想要回應呼叫。 (我認爲 - 如果UIKit實際上延遲了演示文稿可能並不重要。)

0

嘗試使用popoverVC.modalPresentationStyle = UIModalPresentationStyle.PageSheet

+0

這也不起作用。彈出窗口從我的視角開始升起,然後像之前的答案一樣覆蓋整個屏幕。 – wxcoder

+0

更改.popover的.pagesheet。 –