Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone calendar navigation controller

to further my learning, I'm trying to replicate the default iPhone Calendar navigation implementation. What I see in portrait is a semi standard nav bar where selecting a month in the year view pushes the month view and selecting a day of the month pushes the day view.

However, change to landscape we have a segmented control instead of a title, and the title is in the left bar button position. My question is two fold.

First, how should I think about accomplishing the layout changes with the title/segmented control and left bar button when the orientation changes?

Second, what's happening behind the scene in landscape mode with the segmented control? For instance, if the "Day", segmented is the current view, what's happens when a different segment is selected? If "Month" is selected, is the month view pushed on top of the day view? Or, is the day view popped before the week view is pushed? Furthermore, switch back to portrait and it appears that the current view has been pushed on top of the previous view.

I guess I'm having a hard time wrapping my head around what's going on with toggling around the segmented control and making various selections and what not.

Portrait

Landscape

like image 503
Mox Avatar asked Sep 04 '26 18:09

Mox


1 Answers

Firstly I'd not think of it as an 'extended' Navigation Bar, but an additional UIView that is set to be right underneath the Navigation Bar and of the same colour / styling.

I think you need to look at UIContainers and Stacks, both horizontal and vertical.

In this way you would have a UIViewController that controls the UIView that displays the days of the week and handles the animations and states, but in your parent UIViewController, you'd have a UIContainer view that on ViewDidLoad you would set under the Navigation Bar's frame, and then load in the child UIViewControllers View and set it as the container's view.

This allows you to separate the logic out into smaller and much more manageable UIViewControllers and you can keep adding or removing them at runtime depending on device orientation.

Check this for info about UIContainers:

https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html

And look at this for how to use Stacks:

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwjgyMKX4uvjAhUKXRUIHXeGD-8QtwIwAHoECDIQAQ&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dp0X4TnK5m5o&usg=AOvVaw0xdJhCVz3BG5kI2_v7zWe6

Here's another great article about composition with UIContainerViews:

https://medium.com/flawless-app-stories/container-view-controllers-revisited-e076ef38853f

like image 129
SwiftNewbieDoo Avatar answered Sep 06 '26 11:09

SwiftNewbieDoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!