- (void)viewDidLoad
{
[super viewDidLoad];
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
self.navigationController.navigationBar.translucent=YES;
}
// Do any additional setup after loading the view.
}
我不希望我的 scrollView 默认位于 navigationBar 后面。所以我设置了 self.edgesForExtendedLayout = UIRectEdgeNone;。
那个 viewDidLoad 是我所有 viewController 的母亲 viewDidLoad。
没关系。但我喜欢半透明的效果。
当我将self.edgesForExtendedLayout设置为none时,半透明效果似乎消失了。
我如何将其设置为无并仍然获得半透明效果。
我认为一个好的解决方案是安排 ScrollView 的插入。
我做到了
- (void)viewDidLoad
{
[super viewDidLoad];
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
{
//self.edgesForExtendedLayout = UIRectEdgeNone;
self.navigationController.navigationBar.translucent=YES;
self.automaticallyAdjustsScrollViewInsets = YES;
}
// Do any additional setup after loading the view.
}
这就是我得到的:
最佳答案
我现在也有同样的问题。因此,如果您需要保持半透明的导航栏,您应该更改的不是边缘,而是插图。 这是代码,对我有帮助。
if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
CGRect statusBarViewRect = [[UIApplication sharedApplication] statusBarFrame];
float heightPadding = statusBarViewRect.size.height+self.navigationController.navigationBar.frame.size.height;
myContentView.contentInset = UIEdgeInsetsMake(heightPadding, 0.0, 0.0, 0.0);
}
希望这对您有所帮助。
关于objective-c - 当 self.edgesForExtendedLayout = UIRectEdgeNone 时,导航栏不再半透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19239606/