这是我的问题
上下文
我有一个ViewController,当用户在滚动视图中向下时,导航栏变得透明,当用户在滚动视图中向上时,导航栏变得正常。我对UIScrollViewDelegate的方法产生了这种效果。代码如下:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat offset = scrollView.contentOffset.y;
if (scrollView.contentOffset.y < 0){
scrollView.bounces = false;
}else{
scrollView.bounces = true;
}
CGFloat currentAlpha = (offset / 310);
if (currentAlpha < 0) {
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.alpha = 1;
self.navigationController.titleNavBar.alpha = 0; //This property I made in an UINavigationController extension
} else {
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.alpha = 1;
self.navigationController.titleNavBar.alpha = currentAlpha; //This property I made in an UINavigationController extension
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:0.0f/0.0f green:136.0f/255.0 blue:206.00f/255.0f alpha:currentAlpha]];
}
}
使用前面的代码,我得到了效果,但我有一个问题:我无法将其添加到状态栏,因为self。navigationController。导航栏。“半透明”设置为“是”。因此,在iPhone中,状态栏显示为透明,而在iPhone X中,这种透明性比其他iPhone更大(见图)。
有人知道如何使用导航栏和Statsus栏来实现这种透明效果吗?