模态视图是否有可能不能在整个屏幕上填充?

时间:2017-12-23 03:29:08

标签: ios modal-dialog uikit segue

我想提一个在我的应用中创建内容的模态视图,我想要像iOS Mail应用程序这样的风格。撰写新邮件时,它会覆盖除顶部以外的大部分屏幕。我尝试了多种模态segue样式,所有这些都占据了整个屏幕。我明白了: enter image description here

我喜欢这样的事情: enter image description here

我尝试了所有的演示风格。到目前为止,没有代码可以分享,这只是故事板。

1 个答案:

答案 0 :(得分:0)

class ControllerForPresent: UIViewController {

var parentController: UIViewController!

func present(from parent: UIViewController) {
    parentController = parent
    parentController.view.superview!.backgroundColor = .black
    UIApplication.shared.keyWindow!.rootViewController!.addChildController(self)
    view.frame.origin.y = UIScreen.main.bounds.height
    view.frame.size.height = UIScreen.main.bounds.height - 40
    UIView.animate(0.45, damping: 1, velocity: 1, options: .allowUserInteraction) {
        self.parentController.view.transform = CGAffineTransform(scaleX: 0.95, y: 0.95)
        self.view.frame.origin.y = 40
    }
}

@objc private func close() {
    UIView.animate(0.3, animation: {
        self.parentController.view.transform = .identity
        self.view.frame.origin.y = UIScreen.main.bounds.height
    }, completion: {
        self.parentController.view.superview!.backgroundColor = .white
        self.removeFromParent()
    })
}
}

 class ControllerThatPresents: UIViewController {

     private func showAnotherController() {
        let vc = storyboard!.instantiateViewController(withIdentifier: "ControllerForPresentId") as! ControllerForPresent
        vc.present(from: self)
     }
 }

还要向要呈现的控制器添加标识符“ControllerForPresentId”。