Awais Fayyaz
Awais Fayyaz

Reputation: 2415

Restrict the size of pushed view controller to the container view controller

I am implementing filters in my ecommerce iOS app. I want my filter functionality similar to ebay filter functionality.

Like in the gif attached when user taps on sort filter, the next view (maybe a view controller) opens and shows possible sort options. I am trying to replicate this functionality.

enter image description here

What i tried.

I have implemented a container view controller in which i am showing the filter options. when user taps on any filter item, i am performing a push segue(using storyboard) to next view controller in which i am showing relevant filter options

But the problem.

When i tap on any filter item to proceed further, my app opens the next view controller in full screen, not in the bounds of the container view controller.

See the gif

enter image description here

So how to restrict the next view controller's frame to its parent container view controller?

Also the height of the next view controller should be equal to the number of items in it. See the ebay filters gif. (This is secondary requirement)

Any help would be much appreciated.

Upvotes: 1

Views: 448

Answers (2)

Harshal Bhavsar
Harshal Bhavsar

Reputation: 1673

I will suggest your view hierarchy should be like as follows.

Embed your container view controller (main filter screen) inside a navigation controller by going into editor (xcode menu) ==> embed in ==> Navigation Controller (story board should be open).

On didSelect method of container view controller, push your inner filter Controller by either storyboard segue or programmatically.

enter image description here

Upvotes: 1

Sealos
Sealos

Reputation: 562

You need to make the view controller that wants to present define a presentation context, and then on the other view controller, make the presentation overCurrentContext. That should make the other view controller present itself only over the context of the parent.

This is the similar presentation style that is used on popovers.

Upvotes: 0

Related Questions