Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom view embeed in a Navigation Bar

I'm trying to create a navigation bar that looks like (and with the same behaviour) of the Apple one used in the Calendar App. In particular (see pictures below):


Starting navigation bar

Starting Navigation Bar


Ending navigation bar (after push)

Ending Navigation Bar


I have tried to subclass the UINavigationBar and override the sizeThatFits(rect:CGrect)method. This will increase the bar hight but the result with the custom view is not ok, as well as the animation between the "pop/push" and the button alignments (the button stay aligned down instead of up). That solution seems to be a real mess.

Do you now a better solution to embed a custom view in the navbar (exactly how is represented in the images) and make this view part of the navbar animation as well?

edit

I also find these olds questions that may be useful: Change iPhone navigation bar's height, Change UINavigationBar Height,

Also the resizable-navigation-bar that you can find here on GitHub can be useful

Better solutions are welcome

like image 709
GrizzlyBear Avatar asked Jul 31 '15 09:07

GrizzlyBear


1 Answers

I maybe found a good solution provided by Apple itself to fix this "problem".

HERE you can find a sample code about how customise UINavigationBar without interfere too much with orientation, retrocompatibility etc..

Just download the sample code and see the Extended Navbar Example.

If few words they create a custom view attached to the navigation bar that looks like the navbar itself. Apple explain clearly:

This example demonstrates placing a custom view underneath the navigation bar in such a manner that view appears to be part of the navigation bar itself. This technique may be used to create an interface similar to the iOS Calendar app.

I still don't understand how to achieve the correct push animation with this solution but it could be a good starting point. Anyway, this is NOT an embed view.

like image 158
GrizzlyBear Avatar answered Sep 24 '22 03:09

GrizzlyBear