On the Twitter iOS app when you scroll past your name in the profile section below the navigation bar, your name begins to scroll into view on the navigation bar itself and sticks there if you scroll further down.
I'm wondering how to go about implementing a similar effect and what the best method would be. It looks as if:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
Might be a good bet, but not entirely sure how to make it scroll into view rather than simply animating it when reaching a particular top offset.
I'm using a custom header view rather than the UINavigationBar, so doesn't need to be specific to that, but would work best with a UILabel.
Would prefer Objective-C but Swift is welcome.
Lovely example image:
Thanks for the Code Ryan, It works fine in my project. The code has a little mistakes but I fixed it and here is the version in Swift in case anybody need it.
Here I got it working. This ViewController is presented in a simple
UINavigationController
.the code above is good, clear and simple for scrolling of title only.
but if you want to make a view same as Twitter, you can use this tutorial:
http://www.thinkandbuild.it/implementing-the-twitter-ios-app-ui/
this tutorial is implemented in swift.
you can download the source code by clicking on button "Download Source" in end of this tutorial.
or go directly to github: https://github.com/ariok/TB_TwitterUI
below we will explain how implement the fuction scrollViewDidScroll:
1- These are the first lines for the scrollViewDidScroll function:
Here we get the current vertical offset and we initialize two transformations that we are going to setup later on with this function.
2- manage the Pull Down action
3- manage the scroll up/down
4- Apply Transformations