gpt4 book ai didi

ios - 修改 Popover View Controller 的宽度

转载 作者:行者123 更新时间:2023-11-30 14:02:39 24 4
gpt4 key购买 nike

我正在尝试修改弹出窗口的宽度,它是一个 UITableViewController ,以便它只占用父 View 宽度的一半。当点击另一个 UITableView(父 View )中的按钮时,会以编程方式调用弹出窗口。我尝试设置弹出窗口的 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

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

最佳答案

你要求的是

popoverVC?.modalPresentationStyle = .OverFullScreen

这样你就可以让它覆盖整个屏幕。尝试使用:

popoverVC?.modalPresentationStyle = .Popover

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

也应该放在最后,以便代理可以获得它想要响应的调用。 (我认为——UIKit 是否真的延迟了演示可能并不重要。)

关于ios - 修改 Popover View Controller 的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32793970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com