【发布时间】:2015-09-26 05:29:05
【问题描述】:
我正在尝试修改弹出框的宽度,即UITableViewController,以便它只占用父视图宽度的一半。当点击另一个UITableView(父视图)中的按钮时,会以编程方式调用弹出框。我尝试设置弹出框的preferredContentSize 并设置sourceRect,但弹出框仍然占据整个屏幕。
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
由于某种原因,它们都返回 nil
【问题讨论】:
-
现在的陈述不应该是最后一个吗?配置完所有内容后?
-
@Rage 我在创建这个问题之前尝试过,但没有任何区别。至少可以说非常奇怪的行为
标签: ios swift uitableview swift2 uipopovercontroller