弹出显示为全屏
问题描述:
我想显示视图控制器内部的视图控制器。我正在使用popup segue来做到这一点。第二个视图控制器设置如下所示,但无论如何,它都以全屏显示。弹出显示为全屏
func tappedView3() {
// get a reference to the view controller for the popover
let popController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "popoverId")
// set the presentation style
popController.modalPresentationStyle = UIModalPresentationStyle.popover
// set up the popover presentation controller
popController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.up
popController.popoverPresentationController?.delegate = self
popController.popoverPresentationController?.sourceView = m_tumgun // button
popController.popoverPresentationController?.sourceRect = m_tumgun.bounds
// present the popover
self.present(popController, animated: true, completion: nil)
}
// UIPopoverPresentationControllerDelegate method
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
// Force popover style
return UIModalPresentationStyle.none
}
答
您应该使用容器视图这一点。
+0
我红约containerview但我的问题是,我通过一个按钮来打开第二个观点,当新的容器视图中打开该按钮消失。当我搜索时,例如该按钮应该仍在视图中。 –
+0
@EmreÖnder,Container View只是视图。您可以将其添加为主视图控制器的子视图。 –
答
class TablePopupController: UIViewController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
self.modalPresentationStyle = .overCurrentContext
self.modalTransitionStyle = .crossDissolve
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
/// to touch button which pressed
///
/// - Parameter sender: button presse
@IBAction func toDismissView(_ sender: AnyObject) {
self.handler!(nil)
self.dismiss(animated: true, completion: nil)
}
就可以在其他控制器使用它通过以下线
let lifeStyleTablePopup = TablePopupController(nibName: NibName.TablePopupController.rawValue, bundle: nil)
self.present(self.lifeStyleTablePopup, animated: true, completion: {
})
我希望这将有助于你
https://stackoverflow.com/a/39975346/1702413 – TonyMkenu