Skip to content

Instantly share code, notes, and snippets.

@fjolnir
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjolnir/0daa1f68610984eedf43 to your computer and use it in GitHub Desktop.
Save fjolnir/0daa1f68610984eedf43 to your computer and use it in GitHub Desktop.
Caveat: breaks if you start an interactive pop transition and change your mind.
@implementation FStaticNavigationBar {
__weak UIView *_navView;
}
- (void)layoutSubviews
{
[super layoutSubviews];
_navView.hidden = _staticTitleView != nil;
if(_staticTitleView) {
[UIView animateWithDuration:0.3 delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
_staticTitleView.center = _navView
? _navView.center
: (CGPoint) { CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds) } ;
} completion:nil];
[self bringSubviewToFront:_staticTitleView];
}
}
- (void)addSubview:(nonnull UIView *)view
{
[super addSubview:view];
if([NSStringFromClass(view.class) isEqualToString:@"UINavigationItemView"])
_navView = view;
}
- (void)setStaticTitleView:(UIView *)aView
{
[_staticTitleView removeFromSuperview];
_staticTitleView = aView;
[self addSubview:_staticTitleView];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment