【问题标题】:Modify width of Popover View Controller修改 Popover View Controller 的宽度
【发布时间】: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?.sourceViewpopoverPresentationController?.sourceRect

由于某种原因,它们都返回 nil

【问题讨论】:

  • 现在的陈述不应该是最后一个吗?配置完所有内容后?
  • @Rage 我在创建这个问题之前尝试过,但没有任何区别。至少可以说非常奇怪的行为

标签: ios swift uitableview swift2 uipopovercontroller


【解决方案1】:

你要求

popoverVC?.modalPresentationStyle = .OverFullScreen

所以你让它覆盖整个屏幕。尝试使用:

popoverVC?.modalPresentationStyle = .Popover

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

也应该是最后一个,这样代理才能得到它想要响应的调用。 (我认为——UIKit 是否真的在延迟演示可能并不重要。)

【讨论】:

    【解决方案2】:

    尝试使用popoverVC.modalPresentationStyle = UIModalPresentationStyle.PageSheet

    【讨论】:

    • 这也不起作用。弹出框从我的视图底部升起,然后像以前的答案一样覆盖整个屏幕。
    • 将 .pagesheet 更改为 .popover。
    猜你喜欢
    • 1970-01-01
    • 2017-10-15
    • 2019-12-08
    • 2015-05-14
    • 2014-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    相关资源
    最近更新 更多