我可以显示全屏 ViewController,但仍然可以向下滑动以返回父级(启动器)ViewController
Can I have Full Screen ViewController presented, but still able to swipe down, to get back to Parent (launcher) ViewController
在iOS13,当我们呈现一个新的ViewController
let newVC = NewViewController()
self.present(newVC, animated: true)
如下所示,不是全屏,可以向下滑动回到启动状态ViewController
要使其全屏,我们可以使用 .fullScreen
,如下所示。
let newVC = NewViewController()
newVC.modalPresentationStyle = .fullScreen
self.present(newVC, animated: true)
全屏显示如下。但是,它不允许我再向下滑动回到父级。
有没有办法在全屏打开的情况下向后滑动并返回父级?
您可以尝试以下示例:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
//Button is added via storyboard
@IBAction func presentButtonDidTap(_ sender: UIButton) {
let vc = NewViewController()
vc.modalPresentationStyle = .fullScreen
present(vc, animated: true)
}
}
class NewViewController: UIViewController {
override func viewDidLoad() {
self.view.backgroundColor = .gray
let gesture = UISwipeGestureRecognizer(target: self, action: #selector(dismissVC))
gesture.direction = .down
view.isUserInteractionEnabled = true // For UIImageView
view.addGestureRecognizer(gesture)
}
@objc
private func dismissVC() {
dismiss(animated: true)
}
}
在iOS13,当我们呈现一个新的ViewController
let newVC = NewViewController()
self.present(newVC, animated: true)
如下所示,不是全屏,可以向下滑动回到启动状态ViewController
要使其全屏,我们可以使用 .fullScreen
,如下所示。
let newVC = NewViewController()
newVC.modalPresentationStyle = .fullScreen
self.present(newVC, animated: true)
全屏显示如下。但是,它不允许我再向下滑动回到父级。
有没有办法在全屏打开的情况下向后滑动并返回父级?
您可以尝试以下示例:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
//Button is added via storyboard
@IBAction func presentButtonDidTap(_ sender: UIButton) {
let vc = NewViewController()
vc.modalPresentationStyle = .fullScreen
present(vc, animated: true)
}
}
class NewViewController: UIViewController {
override func viewDidLoad() {
self.view.backgroundColor = .gray
let gesture = UISwipeGestureRecognizer(target: self, action: #selector(dismissVC))
gesture.direction = .down
view.isUserInteractionEnabled = true // For UIImageView
view.addGestureRecognizer(gesture)
}
@objc
private func dismissVC() {
dismiss(animated: true)
}
}