我将在Objective-C中找到解决方案,但对我而言不起作用。向下滚动时,我想在“ TableViewController”中隐藏“ NavigationBar”。我这样做是这样的:
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "Test"
self.navigationBar = UINavigationBar(frame: CGRectZero)
self.view.addSubview(navigationBar)
self.navigationBar.pushNavigationItem(self.navigationItem, animated: false)
func layoutNavigationBar() {
self.navigationBar.frame = CGRectMake(0, self.tableView.contentOffset.y, self.tableView.frame.size.width, self.topLayoutGuide.length + 44)
self.tableView.contentInset = UIEdgeInsetsMake(self.navigationBar.frame.size.height, 0, 0, 0)
}
override func scrollViewDidScroll(scrollView: UIScrollView) {
self.layoutNavigationBar()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.layoutNavigationBar()
}
有什么主意在这里吗?“ NavigationBar”在加载时出现,但从不消失。
请参阅我刚刚发布的github上的RRViewControllerExtension。
使用RRViewControllerExtension,您甚至不必#import头文件,所有您需要做的如下:
//typically in your UIScrollViewDelegate method
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
BOOL mode;
if(scrollView.contentOffset.y > 300)
mode = NO;
else
mode = YES;
if(mode != _previewMode)
{
_previewMode = mode;
//force navigation appearance update
[self updateNavigationAppearance:YES];
}
}
-(BOOL)prefersNavigationBarTransparent
{
if(_previewMode)
return NO;
else
return YES;
}
-(nullable UIColor *)preferredNavigationItemColor
{
if(_previewMode)
return [UIColor whiteColor];
else
return [UIColor blackColor];;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句