8

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

Community
  • 1
  • 1
GrizzlyBear
  • 1,098
  • 1
  • 13
  • 27
  • This seems to be a duplicate of question:http://stackoverflow.com/questions/892905/change-iphone-navigation-bars-height which is a duplicate of question:http://stackoverflow.com/questions/892905/change-iphone-navigation-bars-height. Both of these should answer you question, even in details this answer:http://stackoverflow.com/a/7533098/849616. Also why won't you just add a toolbar below navigationBar..? It should look similar. – Nat Jul 31 '15 at 11:53
  • Yes I already seen that question but they was so old that I suppose that something may be changed in the meanwhile. That's why I asked again. :) – GrizzlyBear Jul 31 '15 at 11:55
  • 1
    Then you should at least link that question, as it's just a duplicate right now. First question is updated to iOS 7, so i think it's still valid. Did you read that answer I've linked above? There's a tutorial included. I'd just add a toolbar anyway. It will look perfectly well in your case. Remember that hacking anything in UIKit ends BAD in future iOS releases. Apple stated that navbar has such height and you should stick to it, otherwise the solution may be broken in future iOS releases. – Nat Jul 31 '15 at 11:58
  • You're right. I'll update the question. – GrizzlyBear Jul 31 '15 at 11:59

1 Answers1

11

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.

GrizzlyBear
  • 1,098
  • 1
  • 13
  • 27