呈现视图控制器时未加载/缺少UILabel

时间:2019-06-13 08:38:56

标签: ios swift

有人与盆景合作吗? Github链接位于:Here

我尝试使用其中

的手势来推动viewController
    @objc func upSwiped(gesture: UISwipeGestureRecognizer) -> Void {
    if gesture.direction == UISwipeGestureRecognizer.Direction.up {
        print("Swiped Up")

        let vc = PromoDetailsViewController()
        vc.transitioningDelegate = self
        vc.modalPresentationStyle = .custom
        present(vc, animated: true, completion: nil)
    }
}

要使用盆景,我需要进行

这样的扩展
extension YourViewController: BonsaiControllerDelegate {

// return the frame of your Bonsai View Controller
func frameOfPresentedView(in containerViewFrame: CGRect) -> CGRect {

    return CGRect(origin: CGPoint(x: 0, y: containerViewFrame.height / 4), size: CGSize(width: containerViewFrame.width, height: containerViewFrame.height / (4/3)))
}

// return a Bonsai Controller with SlideIn or Bubble transition animator
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {

    // Slide animation from .left, .right, .top, .bottom
    return BonsaiController(fromDirection: .bottom, blurEffectStyle: .light, presentedViewController: presented, delegate: self)



    // or Bubble animation initiated from a view
    //return BonsaiController(fromView: yourOriginView, blurEffectStyle: .dark,  presentedViewController: presented, delegate: self)
}
}

在我的下一个viewController中,应该将其从屏幕的底部滑动到一半来显示,但是那里的标签都丢失了。我怀疑它没有加载,不确定要采取什么步骤。我目前的结果是

enter image description here

1 个答案:

答案 0 :(得分:1)

尝试从情节提要中实例化视图控制器,而不是let vc = PromoDetailsViewController()

let storyboard = UIStoryboard(name: "YOUR STORYBOARD NAME", bundle: Bundle.main)

guard let vc = storyboard.instantiateViewController(withIdentifier: "YOUR VIEW CONTROLLER IDENTIFIER") as? PromoDetailsViewController else {
    fatalError("Error! Could not instantiate PromoDetailsViewController")
}