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 stic
Here I got it working. This ViewController is presented in a simple UINavigationController
.
@interface ViewController ()
{
UIScrollView *titleView;
UIScrollView *contentView;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self.view setBackgroundColor:[UIColor lightGrayColor]];
[self setTitle:@"My Title"];
titleView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 44.0)];
[titleView setContentSize:CGSizeMake(0.0, 88.0)];
[self.view addSubview:contentView];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 44.0, CGRectGetWidth(titleView.frame), 44.0)];
[titleLabel setTextAlignment:NSTextAlignmentCenter];
[titleLabel setFont:[UIFont boldSystemFontOfSize:17.0]];
[titleLabel setText:self.title];
[titleView addSubview:titleLabel];
self.navigationItem.titleView = titleView;
contentView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[contentView setContentSize:CGSizeMake(0.0, 4000.0)];
[contentView setDelegate:self];
[self.view addSubview:contentView];
UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(self.view.bounds), 44.0)];
[contentLabel setTextAlignment:NSTextAlignmentCenter];
[contentLabel setFont:[UIFont boldSystemFontOfSize:17.0]];
[contentLabel setText:self.title];
[contentView addSubview:contentLabel];
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint contentOffset = CGPointMake(0.0, MIN(scrollView.contentOffset.y + 64.0, 44.0));
[titleView setContentOffset:contentOffset];
}
@end