objective-c - 当 self.edgesForExtendedLayout = UIRectEdgeNone 时,导航栏不再半透明

标签 objective-c ios7

- (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时,半透明效果似乎消失了。

我如何将其设置为无并仍然获得半透明效果。

enter image description here

enter image description here

我认为一个好的解决方案是安排 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.
}

这就是我得到的:

enter image description here

最佳答案

我现在也有同样的问题。因此,如果您需要保持半透明的导航栏,您应该更改的不是边缘,而是插图。 这是代码,对我有帮助。

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/

相关文章:

ios - 带有圆角的 UITextField - IB 中运行时属性中的设置层不起作用

iOS 7 仅在某些时候使用自定义交互过渡

ios - iOS 7 UIImage中的奇怪错误(延迟后未显示或显示)

objective-c - 在核心数据中搜索 NSDate 问题

Objective-C 静态类级别变量

objective-c - SKStoreProductViewController 给出 Domain=SKErrorDomain Code=5 iOS7 错误

iphone - 如何从Game Center获取本地玩家分数

ios - 是否可以通过编程方式关闭 iOS 中的拨号辅助功能?

iphone - 检查 NSNumber 是否有尾随 .00 数字

ios - 我可以在要提交给应用商店的应用程序中使用SpringBoardServices吗?