在iOS7中,在Safari中导航栏在滚动时会自动缩小。Facebook中的导航栏也是如此,甚至会完全消失。
你如何实现这种行为呢?我猜你还必须动态调整contentOffset,而且我猜这也会与默认的刷新控件冲突,是不是?
你如何实现这种行为呢?我猜你还必须动态调整contentOffset,而且我猜这也会与默认的刷新控件冲突,是不是?
这不是正确的做法,但对我有效。我在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)。