Take UISearchDisplayController full screen with UIView acting as UINavigationBar - ios

I am having a hard time adding a UISearchDisplayController to my app. The situation is this: The primary navigation in the app takes place by scrolling between UITableViewControllers whose table views are all subviews of a UIScrollView. Each of these has a UISearchDisplayController for searching the contents within each UITableView.
I also have a UIView outside of the UIScrollView which takes up the entire width of the screen and 85 pixels of the height, located at the very top of the interface. This acts as a kind of UINavigationBar, but due to the very custom nature of this element, I have made it a subclass of UIView.
My problem is that when you activate the UISearchBar, I want the "navigation bar" to move off the screen and the UISearchBar to take its place (like in the native Mail app where tapping the search field hides the navigation bar). It seems to me like I not only have to manually hide the "navigation bar" but also expand the size of the UIScrollView and all of its nested UITableViews in order to achieve this.
I am still a novice, so I am completely puzzled as to how to do this. Is there a simple solution or do I have to do this all manually and/or restructure my code in order to create the desired effect?

Related

Scrolling effect in ViewController

How can I achieve when the user scrolls in the ViewController down to make the highlighted text show up in NavigationBar and when the user scrolls back up to make it disappear again? Similar to Apple's one in Settings app in Apple advertising (https://imgur.com/0FeFJ3s)
Edit:
Looking at the image you posted, this seems to be the default transition a large style navigation bar gives you. The only tweak that's been done is centering the title text.
Original answer:
The text in the navigation bar follows the .title property of your view controller. However, setting the title is not animated. Depending on your use case, that may or may not be enough.
If you want to do things a bit more fancy, you have some control over the .navigationItem.titleView in a view controller. This way you can use a custom view in the navigation bar. Using this, and a bit of fancy programming, you can animate things there.
Last, you can read the scroll position of a UITableView or a UIScrollView by implementing the scroll view's delegate's scrollViewDidScroll method. How you know where the labels that are interesting are depends on the content of your scrollView, so I can't answer that for you.

Add a UINavigationBar to a UIView using Autolayout

I have a modal view that I'm presenting over the current view that has a UINavigationBar as a subview. Everything's working great, except that the UINavigationBar doesn't want to behave according to the autolayout constraints. Everything else in the view behaves as desired.
For some reason, the left and right bar button items are cut off on the edges of the view. I inspected the view at runtime to reveal that the total width of the UINavigationBar is the right width, but the bar buttons aren't conforming.
I also checked to make sure I didn't have negative margins or some other anomaly in the constraint definitions.
I have also tried setting the frame of the UINavigationBar manually, but it yielded no improvement.
Problematic View
Constraints
I'd like to keep the UINavigationBar, because it gets styled globally with the rest of my app (as opposed to creating a custom UIView imitation and styling it individually). Does anyone know what handle to jiggle to get the bar button items to conform to the right width?

Best approach for creating this custom UINavigationbar ios

I am creating a UINavigationBar that will expand and contract in various states. The top image is when it is in a contracted state with a transparent background. The lower image represents when it has expanded with a background and search bar. As the user scrolls down the nav bar background would animate in and expose the search field.
Can someone suggest the best way to build this?
So far I've explored subclassing the UINavigationBar, but I've been having a really tough time with the placement of the items within the nav bar or hooking that view up to a xib. I've also see examples where the extended content is just a UIview anchored to the top of the view controller top margin, but then I'm splitting the appearance of my nav into two views which will make the animation problematic.
According to the answer to UISegmentedControl below UINavigationbar in iOS 7 it can be accomplished using a UIToolBar and some delegate methods.
You might have to tweak it a little bit however, to fit the search bar that you want to include.

Empty navigation bar appearing in subview

I am trying display a UITableView within a larger UIView in an iPad app, mainly because the data is pretty sparse and I'd like to have the table be a smaller area over a background image, rather than taking up the whole screen. The parent UIViewController is correctly set as the table data source and delegate, and the table looks/functions like it should. The whole view is embedded in a navigation controller; the overall UIView shows a navigation bar, as it should, that I can configure normally.
The problem is the UITableView subview also shows blank space at the top for a navigation bar--empty space above the first cell--and I can't figure out how to get rid of it. I know the space is related to the navigation controller, because when I delete the embed link in the storyboard, the space goes away. The table view doesn't present a UINavigationBar property or any other navigation-related properties that I can try to nullify.
I would post a screen shot but I don't have the rep yet.
Can anyone explain where the space is coming from and how to nix it?
I suspect the answer is related to the Top Layout Guide for the view, but I can't diagnose the specific problem.
Here's a workaround from the storyboard: Insert a UIView in the scene, then drag the UITableView into it as a subview. Check the box for the new UIView's "Clip Subviews" in the attribute window, and then use it as a mask, basically, to cover the undesired top margin of the table view. It works and doesn't require any coding, but there has to be a better way.

Creating custom implementation of navigation bar

I wish to create a view similar in behavior to the UINavigationBar.
I cannot simply customize the bar as I want the space to be taller and I want to have several other subviews on it other than just UIBarButtonItems. So, I want to be able to create a similar implementation including the floating/translucency effect.
I good example of this is the address bar in Safari in iOS 7. The UITextField on the bar is something that cannot be added on the default UINavigationBar. Nevertheless, the Safari bar still has the transparency.
I do not want it to shrink like it does in Safari when scrolling down, I simply want it to remain just like a UINavigationBar would. I was thinking about adding a subview to the root UIScrollView, but this would scroll along with everything. I want this to remain at the top, but I want other elements to be able to scroll.
How would I go about implementing this?
If you are confident that you can't to this with the default UINavigationBar, you could shrink (from the top) the UIScrollView with whatever the size the custom UINavigationBar is and then add the navbar as a subview to the root view at (0,0) coordinates. It will be independent from the scroll view.
On the other hand, if you need this to be persistent through the application and use it in all of the screens, it will be wise to make some changes starting for the AppDelegate, but that's for another question.
For the iOS 7 transparent-style part, look here: FXBlurView. Best of luck!

Resources