在iOS7中,Safari中的navigationBar会在滚动时自动缩小.
Facebook中的navigationBar也是如此,甚至完全消失了.
Facebook中的navigationBar也是如此,甚至完全消失了.
你会如何自己实现这种行为?
我想你还必须动态调整contentOffset,我猜这也会与默认的Refresh Control冲突,不是吗?
解决方法
这不是正确的做法,但它对我有用.我在UINavigationBar上创建了类别并覆盖了sizeThatFits:就像这样:
- (CGSize)sizeThatFits:(CGSize)size { CGSize cSize = self.frame.size; BOOL isPortrait = UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]); CGFloat originalHeight = isPortrait ? 44: 32; cSize.height = self.tag > 0 ? originalHeight / 2 : originalHeight; return cSize; }
然后,当我需要缩小导航栏(在滚动视图的委托方法中):
CGRect navBarFrame = self.navigationController.navigationBar.frame; BOOL isPortrait = UIInterfaceOrientationIsPortrait(self.interfaceOrientation); CGFloat originalHeight = isPortrait ? 44: 32; navBarFrame.size.height = expand ? originalHeight : originalHeight / 2; self.navigationController.navigationBar.tag = expand ? 0 : 1; [UIView animateWithDuration:0.25 animations:^{ self.navigationController.navigationBar.frame = navBarFrame; [self.navigationController.view setNeedsLayout]; }
此外,您可能希望在动画中隐藏导航项(如UIBarButtonItems).