尺寸较小的uiviewcontroller

时间:2018-11-10 12:07:49

标签: ios swift uiviewcontroller toast presentviewcontroller

我是iOS开发的新手,正在尝试通过使用较小尺寸的UIViewController并以模态形式进行自定义烤面包。我希望在显示视图控制器时,背景屏幕保持响应(可单击/可滚动),但此刻,背景屏幕变得无响应,直到关闭所显示的视图控制器为止。任何在正确方向上的帮助将不胜感激。 谢谢!

修改1: 这是NotificationToastViewController内部的函数,被调用来显示吐司。

class func popup(with presentable: NotificationToastPresentable, onViewDidAppear: (() -> ())? = nil, onDismiss: ((CloseStatus) -> ())? = nil, bool1: Bool = false, bool2: Bool = false) {
    let popupViewController = NotificationToastViewController()
    popupViewController.modalTransitionStyle = .crossDissolve
    popupViewController.modalPresentationStyle = .overCurrentContext
    let _ = popupViewController.view
    popupViewController.configureWith(presentable)
    popupViewController.onViewDidAppear = onViewDidAppear
    popupViewController.onDismiss = onDismiss

    if bool1 {
        popupViewController.statusLabelConstraintToBottom?.constant = 12.0
        popupViewController.statusLabelLeadingConstraint?.constant = 10.0
        popupViewController.statusLabelConstraintWithIcon?.isActive = false
    } else {
        popupViewController.statusLabelConstraintToBottom?.isActive = false
        popupViewController.statusLabelLeadingConstraint?.isActive = false
    }

    if bool2 {
        popupViewController.heightConstrainOfCtaButton?.isActive = false
    }
    UIApplication.shared.topMostViewController()?.present(popupViewController, animated: true)
}

这是xib中的视图层次结构: This is the view hierarchy in the xib:

1 个答案:

答案 0 :(得分:0)

您可以执行以下操作:

var vc = SecondController()
    self.addChild(vc)
    self.view.addSubview(vc.view!)
    vc.view.translatesAutoresizingMaskIntoConstraints = false
    vc.view.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: 200).isActive = true
    vc.view.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 300).isActive = true
    vc.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor, constant: 0).isActive = true
    vc.view.rightAnchor.constraint(equalTo: self.view.rightAnchor, constant: 0).isActive = true

其中SecondViewController是另一个ViewController类,您必须将其作为子Controller添加到主控制器,然后设置第二个控制器的视图的约束。我相信这种实现的结果就是您要实现的目标。