如何在iOS 7中的导航栏上获得模糊和半透明效果?

Pwn*_*ner 11 cocoa-touch uinavigationbar ios ios7

问题

我的应用程序似乎布局正确,但我无法实现iOS 7着名的模糊半透明效果.我看起来不透明.

在此输入图像描述

期望的效果

我正试图获得更明显的模糊效果,例如Apple的预告片应用:

在此输入图像描述

半透明

在我的UINavigationController的子类中,我使导航栏半透明:

- (id)initWithRootViewController:(UIViewController *)rootViewController
{
    if (self = [super initWithRootViewController:rootViewController]) {
        self.navigationBar.translucent = YES;
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

色调

在我的UIApplicationDelegate的子类中,我设置了导航栏的色调颜色.我发现色调的颜色没有区别.也就是说,使用0.1的α不会导致条形变得更透明.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    [[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
}
Run Code Online (Sandbox Code Playgroud)

边缘

在我的内容视图控制器中,我将边缘设置为,UIRectEdgeNone以便顶部不会被导航栏切断.如果我使用默认设置UIRectEdgeAll,导航栏将永久覆盖我的内容的顶部.即使我生活在这种异常中,UIRectEdgeAll仍然没有启用半透明效果.

- (void) viewDidLoad
{
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
}
Run Code Online (Sandbox Code Playgroud)

编辑:尝试边缘

广告在@rmaddy的评论中指出,问题可能与edgeForExtendedLayout有关.我找到了一个全面的教程edgesForExtendedLayout并试图实现它:

- (void) viewDidLoad
{
    [super viewDidLoad];

    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.extendedLayoutIncludesOpaqueBars = NO;
}
Run Code Online (Sandbox Code Playgroud)

那没起效.首先,没有半透明效应.其次,我的内容被删除了.在下面带有上述代码的示例页面上,头像最初被导航栏覆盖,很难滚动到.您可以下拉以查看头像的顶部,但是当您放开时,页面会自动反弹并且头像会再次被遮挡.

在此输入图像描述

Pwn*_*ner 5

问题是由第三方下拉到刷新视图EGORefreshTableHeaderView引起的,这是在iOS 6引入系统刷新控制之前普遍使用的.

在此输入图像描述

这个视图混淆了iOS 7,使它认为内容比实际更高.对于iOS 6和7,我有条件地切换到使用UIRefreshControl.现在导航栏不会切断我的内容.我可以使用UIRectEdgeAll我的内容进入导航栏下方.最后,我用较低的alpha着色我的导航栏以获得半透明效果.

// mostly redundant calls, because they're all default
self.edgesForExtendedLayout = UIRectEdgeAll;
self.automaticallyAdjustsScrollViewInsets = YES;
self.extendedLayoutIncludesOpaqueBars = NO;

[[UINavigationBar appearance] setTintColor:[UIColor colorWithWhite:0.0 alpha:0.5]];
Run Code Online (Sandbox Code Playgroud)