SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.31k stars 743 forks source link

Running SwiftMessagesSegue programmatically #340

Closed ZebedeeTR closed 5 years ago

ZebedeeTR commented 5 years ago

Hello there, I am creating the destinationView from the xib file. I couldn't run SwiftMessagesSegue with programmatically. I didn't find out where I made a mistake.

I create destinationView like this let destinationVC = AddNewServerVC(nibName: "AddNewServerVC", bundle: nil)

Then I try to show it as follows. I see only shadow. let segue = VeryNiceSegue(identifier: nil, source: self, destination: destinationVC) segue.perform()

When I write this way, the view is displayed smoothly. destinationVC.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext destinationVC.modalTransitionStyle = UIModalTransitionStyle.crossDissolve self.present(destinationVC, animated: true, completion: nil)

The VeryNiceSegue class is defined as in your instance.

What am I missing?

wtmoose commented 5 years ago

Not sure, but here's a sample project that you can use for reference:

SwiftMessagesTest.zip

My initial guess is that your view controller's Auto Layout constraints are doing something weird, maybe resulting in zero height.

The SwiftMessages view hierarchy is MaskingView > BaseView > CornerRoundingView > Your View. I suggest that you inspect the view hierarchy to see if "Your View" is there. If it isn't, there may be a SwiftMessages problem. Another quick way to see if your view is there is to set destinationVC.preferredContentSize = CGSize(width: 0, height: 400), which adds an explicit 400pt height constraint to your view controller.

Let me know what you find.

ZebedeeTR commented 5 years ago

Hi. Thanks for the help.

I couldn't figure out why my view's height comes from zero. I added the same View to your Test project, but it's okay there. :))

destinationVC.preferredContentSize = CGSize(width: 0, height: 400) This code solves my problem.

I'm adding my project, if you want to examine it :)

ServerMonitor.zip

wtmoose commented 4 years ago

I took a look at your project and there are a couple of things:

  1. Your SwiftMessage is a little bit out of date. If you update to 7.0.0, SwiftMessages configures a very low-priority height constraint of 350pt as a default in case you don't specify a height.
  2. Your view controller's Auto Layout constraints are not well-defined in that there's no intrinsic height.

You can use preferredContentSize to specify your height, but in my opinion, it is better if your view controller has sufficient Auto Layout constraints such that it has an intrinsic height.

ZebedeeTR commented 4 years ago

Thanks for additional info.

Best regards.