52inc / Pulley

A library to imitate the iOS 10 Maps UI.
https://cocoapods.org/pods/Pulley
MIT License
2.02k stars 265 forks source link

Using Pulley with pre-existing, complex view controllers #229

Closed Zacharyg88 closed 6 years ago

Zacharyg88 commented 6 years ago

Hello!

We are a fairly complex application looking to incorporate Pulley into our MapBox view controller and a form of a pin detail view controller. I'm having issues setting up Pulley into our system without re-making our layouts. I'm sure I'm just missing something basic but instead of taking hours and hours trying to debug, I thought I'd go straight to the source. I can't share code due to non-disclosure stuff so I'm wondering if I could get some sample code as to how one might use pre-made UIViewControllers with Pulley.

Thanks!

amyleecodes commented 6 years ago

You can use pre-made view controllers with Pulley the same way you can use a brand new view controller with Pulley. You just need to make sure your view controllers implement the appropriate delegates.

A few things to note:

  1. Because of how Auto Layout with manual child view controller is currently handled, the initial size of the view controller's view is (0, 0). This will cause constraint errors if you have constants for widths. You can workaround this by setting constant width constraints to a priority of less than 1000.

  2. Pulley makes your drawer view controller 20pt too long in order to account for the 'bounce' animation, so your layout needs to be aware that the bottom 20pt will be off screen. Typically this is handled in UITableView / UIScrollView by setting a 20pt contentInset on the bottom.

The sample project in the repo has a basic implementation of Pulley with some basic features / techniques. I recommend starting there and if you have a specific question, I'm happy to help.

Zacharyg88 commented 6 years ago

Awesome. Thanks! I'll dig into the sample and let you know if something more specific comes up!

Zacharyg88 commented 6 years ago

Ok, after digging through the sample project, I'm concerned that I'm going to have to add a PulleyViewController into my stack. We are running off of a tabBar and adding a PulleyViewController into that chain, unless I'm way off in my thought process, is going to be a pain. In lieu of this, I'm trying to implement the PulleyViewController programmatically via the viewController I want to be the PrimaryContentViewController but I'm getting a nil value for my self.pulleyViewController.primaryContentContainerView when I try to do this. I'm I thinking about this incorrectly?

amyleecodes commented 6 years ago

You should not subclass PulleyViewController or use it as your primary content view controller.

It’s meant to be used similar to a UINavigationController. It manages your 2 view controllers: 1 primary content view controller and 1 drawer view controller. Don’t customize or use PulleyViewController to have your UI content in it.

amyleecodes commented 6 years ago

I’m not familiar with your codebase, however I’ve seen Pulley implemented into incredibly large / complex code bases in under an hour.

Most people use PulleyViewController as an item in the tab bar controller and then make the primary content view controller of Pulley the view controller that was previously managed by the tab bar controller.

Zacharyg88 commented 6 years ago

Ok, so you're saying that in our tab bar controller, instead of navigating to our map view controller, on the selection of the map tab we should navigate to the Pulley View Controller as is, and house the map view controller within the pulley view controller ?

amyleecodes commented 6 years ago

Yes, using the same pattern as the sample project. (Can be done programmatically or via IB)

Zacharyg88 commented 6 years ago

and it's as simple as what you have in the readme? I think I'm overthinking this...

amyleecodes commented 6 years ago

Yep! It’s very simple. It’s like adding a navigation controller or tab bar controller into the middle of a hierarchy. (Slightly more complicated because of having to deal with the container VCs if you use IB).

Zacharyg88 commented 6 years ago

gotcha! Hey, thanks for taking the time to help me with this! Im new to the swift world so I really appreciate you walking me through it.

amyleecodes commented 6 years ago

No problem! Happy to help.

Zacharyg88 commented 6 years ago

Awesome! So I've been able to get pulley into the system, but I've noticed that the view I've setup as the primaryContentView isn't laying out the same as it was. Is the pulleyViewController manipulating the layout of the views? Where can I edit this?

Thanks!

amyleecodes commented 6 years ago

PulleyViewController doesn’t affect your view’s layout, it just controls the frame size and location of the view controller view (which is necessary).

Just to be clear, you’re not manually assigning a primaryContentView, correct? That should be handled automatically when you give Pulley it’s primary content view controller.

You shouldn’t add views directly to Pulley’s view hierarchy (in its view controller) on your own as Pulley manages its subviews. Everything should be contained in either your primary content view controller’s view or your drawer view controller’s view.

If you’re using IB, note that the size / positioning of the container views you use to connect VCs to Pulley ignores their size and location. In addition, any other views you add to Pulley are ignored (or rather, treated as if they don’t exist...which may have side effects).

In addition,

Zacharyg88 commented 6 years ago

Sorry, yes, I'm assigning the Pulley a primaryViewController, and that VC's View is not the same height I expect it to be. Where can I manipulate that size?

amyleecodes commented 6 years ago

The height will be the same as the height of PulleyViewController, which is determined by how you present it. (Generally fullscreen unless you used a different presentation style). It’s equicalent to presenting your view controller using the same presentations style as you used for Pulley.

You can’t change the size, it’s required to be the same for the component to work. If you’re having layout or size issues, the problem is external to Pulley. Ensure you’re not manually changing your view controller’s frame, position, or Auto Layout setting anywhere.

I’m assuming you haven’t modified PulleyViewController in any way. If you have, it’s likely you introduced a layout issue.

Zacharyg88 commented 6 years ago

Hmmm... It's just odd that the only change that's happened is that I've introduced pulley, and now the views don't layout correctly... The viewController being used as the Primary does have several "peripheral" views that live "off screen" and are pulled in when necessary. Would this be an issue?

amyleecodes commented 6 years ago

It shouldn’t be an issue unless you’re using hard coded size values, or have issues with your layout constraints. If your views don’t have constraints, (and are loaded from IB) then they’ll be the size that they are in IB (which will be smaller than normal due to being loaded at the size of the container view). This can be fixed by adding constraints or correcting your constraints, as they would’ve been relying on a default frame size from IB, which isn’t good practice.

Zacharyg88 commented 6 years ago

I'm hard coding layoutconstraint constants in order to "fly" views in and out, but I'm not constructing CGRect frames or anything like that programatically.

amyleecodes commented 6 years ago

That should be fine as long as everything has constraints for its width/height/position. If anything relied on just staying the size it was in IB, then it would have issues.

I’ve never heard of someone encountering an issue with layouts being different when using Pulley. It’s effectively the same as using a tab bar controller or navigation controller- it moves / adjusts the view controller’s view, but doesn’t touch whatever you have inside.

Zacharyg88 commented 6 years ago

Ok, I'll keep digging to see if something is getting manipulated somewhere else. Thanks!

Zacharyg88 commented 6 years ago

Other than the above, everything is working excellently!

amyleecodes commented 6 years ago

Glad to hear it!

parvez-keeptruckin commented 2 years ago

I am a new user to pulley library. I have added pulley view controller as one of the top level view controller (V1) for a tab of a tab bar controller. What is happening is that when a view controller presented over V1 and dismissed then V1 is going slightly behind the tab bar and do not keep itself above tabBar. is there anything we need to do in case of tabBar controller using pulley ?