Scrolling effect in ViewController - ios

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.

Related

In iOS, is there a way to add (overlay) a subview of a UIBarButtonItem image without it moving the buttons already in the bar?

I have my swift 5 app working and I'm now adding a 'tool tips' feature, explaining what each part of the screen does.
The approach I have taken is from an article online - add a subview of grey to dim the background, then to that, add a subview of the item being described again, so it is now highlighted, then also, add a subview of an explainer bubble to explain the item highlighted.
This works fine, so long as the UIView I'm using isn't from a UIBarButtonItem. When it is, the bar buttons underneath the grey screen move around to accomodate what they believe is another bar button being added, which causes everything to miss-align. Other buttons do not have this problem, only UIBarButtons.
Any advice is greatly appreciated. Thanks.
Are you adding the duplicate subview to the bar itself? It'd probably be better to add it to the screen rather than the bar so it doesn't affect the bar's layout. In order to get its frame relative to the view controller so you can display your duplicate in the correct position, you could use:
barButtonItem.convert(barButtonItem.bounds, to: self.view)
Assuming self is a UIViewController.

scrollview on top of navigation bar and toolbar?

I want to know how, if possible, one can keep the scrollview on top of the navigation bar. When I put the scrollview on my view controller it covers the whole screen except for the navigation bar and toolbar. I want to keep it on top of everything.
Use containerView to achieve this because containerView can contain Navigation controller within it like other controller.
And Add scrollView within containerView like below shown -
Hope it will work for you :)
I don't think there is a simple way to put the scroll view "on top of" the navigation bar, and it is certainly something that Apple Devs never intended to be done. Generally (although certainly not always) that means that if you want your code to work consistently as new versions of Swift and iOS are released, you shouldn't do it. The other reason you shouldn't do it (probably) is that unless you setup some sort of fancy "touch through" system you would never be able to actually use the nav bar, at which point you might as well just save the trouble and not have a nav bar in the first place. You can, however, easily check a box in your storyboard to have the scrollview go under the nav bar, and have the nav bar be translucent so that you can see the scroll view content under it.
Good luck!
I think preset modal(UIModalPresentationOverFullScreen) is what you're looking for.

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.

Take UISearchDisplayController full screen with UIView acting as UINavigationBar

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?

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