iPhone 弹出窗口上的导航栏
Navigation bar on iPhone popover
我对生活的要求不多,但我愿意付出很多,以了解如何在这个弹出窗口上获得导航栏:
这是我的故事板:
这是我展示弹出窗口的代码:
@IBAction func doButton(_ sender: Any) {
let vc = PopViewController()
vc.preferredContentSize = CGSize(width: 260,height: 300)
vc.modalPresentationStyle = .popover
vc.view.backgroundColor = UIColor.green
if let pres = vc.presentationController {
pres.delegate = (self as UIAdaptivePresentationControllerDelegate)
}
self.present(vc, animated: true)
if let pop = vc.popoverPresentationController {
pop.sourceView = (sender as! UIView)
pop.sourceRect = (sender as! UIView).bounds
pop.backgroundColor = vc.view.backgroundColor
}
}
}
extension ViewController : UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .none
}
}
(感谢@matt,顺便说一句,上面的代码!)
我在 Google 上到处搜索,但没有找到我能理解的答案。我试图在 Storyboard 中添加 nav bar
,但没有骰子——唯一接受它的元素是 table view
.
中的 prototype cell
请不要重定向到 7 年前写的东西——我已经阅读了其中的大部分内容,并且我现在正在使用 Swift。当然,我可能忽略了一个明确的答案,如果是这样的话,我会谦虚和忏悔。但与此同时,如果您能得到帮助,我将不胜感激!
谢谢!
将您的右侧 tableview 控制器更改为具有 tableViewController root 的导航控制器。导航控制器获取标识符:"navigation".
现在可以修改doButton函数的第一段代码,其余保持不变
@IBAction func doButton(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "navigation") as! UINavigationController
vc.preferredContentSize = CGSize(width: 260,height: 300)
vc.modalPresentationStyle = .popover
vc.view.backgroundColor = UIColor.green
if let pres = vc.presentationController {
pres.delegate = (self as UIAdaptivePresentationControllerDelegate)
}
self.present(vc, animated: true)
if let pop = vc.popoverPresentationController {
pop.sourceView = (sender as! UIView)
pop.sourceRect = (sender as! UIView).bounds
pop.backgroundColor = vc.view.backgroundColor
}
}
最后,您将在弹出窗口中看到导航栏。
我对生活的要求不多,但我愿意付出很多,以了解如何在这个弹出窗口上获得导航栏:
这是我的故事板:
这是我展示弹出窗口的代码:
@IBAction func doButton(_ sender: Any) {
let vc = PopViewController()
vc.preferredContentSize = CGSize(width: 260,height: 300)
vc.modalPresentationStyle = .popover
vc.view.backgroundColor = UIColor.green
if let pres = vc.presentationController {
pres.delegate = (self as UIAdaptivePresentationControllerDelegate)
}
self.present(vc, animated: true)
if let pop = vc.popoverPresentationController {
pop.sourceView = (sender as! UIView)
pop.sourceRect = (sender as! UIView).bounds
pop.backgroundColor = vc.view.backgroundColor
}
}
}
extension ViewController : UIPopoverPresentationControllerDelegate {
func adaptivePresentationStyle(for controller: UIPresentationController, traitCollection: UITraitCollection) -> UIModalPresentationStyle {
return .none
}
}
(感谢@matt,顺便说一句,上面的代码!)
我在 Google 上到处搜索,但没有找到我能理解的答案。我试图在 Storyboard 中添加 nav bar
,但没有骰子——唯一接受它的元素是 table view
.
prototype cell
请不要重定向到 7 年前写的东西——我已经阅读了其中的大部分内容,并且我现在正在使用 Swift。当然,我可能忽略了一个明确的答案,如果是这样的话,我会谦虚和忏悔。但与此同时,如果您能得到帮助,我将不胜感激!
谢谢!
将您的右侧 tableview 控制器更改为具有 tableViewController root 的导航控制器。导航控制器获取标识符:"navigation".
现在可以修改doButton函数的第一段代码,其余保持不变
@IBAction func doButton(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "navigation") as! UINavigationController
vc.preferredContentSize = CGSize(width: 260,height: 300)
vc.modalPresentationStyle = .popover
vc.view.backgroundColor = UIColor.green
if let pres = vc.presentationController {
pres.delegate = (self as UIAdaptivePresentationControllerDelegate)
}
self.present(vc, animated: true)
if let pop = vc.popoverPresentationController {
pop.sourceView = (sender as! UIView)
pop.sourceRect = (sender as! UIView).bounds
pop.backgroundColor = vc.view.backgroundColor
}
}
最后,您将在弹出窗口中看到导航栏。