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

来源:互联网 发布:西安美林数据是外包 编辑:程序博客网 时间:2024/06/08 17:27

问题

我的应用程序出现,要订的正确,但我不能达到模糊的半透明效果的 iOS 7 是著名的。矿井显示为不透明。

enter image description here

预期的效果

我想获得更明显的模糊效果,如苹果的拖车 app:

enter image description here

半透明

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

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

色调颜色

在我的 UIApplicationDelegate 的子类,我设置导航栏中的色调颜色。我发现色调颜色的 alpha 没有区别。也就是说,使用 alpha 0.1 不会导致要变得更透亮的栏。

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

边缘

在我的内容视图控制器中,我将设置边缘为 UIRectEdgeNone 这样顶部的导航栏不会砍。如果要使用默认的 UIRectEdgeAll ,导航栏将会永久地盖顶部的我的内容。即使我要住在一起这种异常, UIRectEdgeAll 仍然不会启用半透明效果。

- (void) viewDidLoad{    [super viewDidLoad];    self.edgesForExtendedLayout = UIRectEdgeNone;}

编辑: 试验与边缘

@rmaddy 在评论中所指出的广告问题可能与 edgesForExtendedLayout。我发现综合教程 edgesForExtendedLayout ,并试图实现它:

- (void) viewDidLoad{    [super viewDidLoad];    self.edgesForExtendedLayout = UIRectEdgeAll;    self.automaticallyAdjustsScrollViewInsets = YES;    self.extendedLayoutIncludesOpaqueBars = NO;}

它不工作。首先,那里是没有半透明效果。第二,我的内容的顶部被切掉。在上面的代码与以下示例页上,神通最初由导航栏和它是很难向滚动。你可以拉下,看到顶部的化身,但当你放开,页面会自动弹起来,神通将会再次被遮掩。

enter image description here

解决方法 1:

问题是由第三方拉下来刷新视图EGORefreshTableHeaderView,而普遍地使用了之前的 iOS 6 介绍系统刷新控制引起的。

enter image description here

这种观点混淆了 iOS 7,让它认为内容是比真的很高。Ios 6 和 7,我已经有条件地切换到使用UIRefreshControl。现在的导航栏不会砍掉我的内容。我可以使用 UIRectEdgeAll ,使我下面的导航栏的内容走。最后,显示我的导航栏与较低的 α 要获得半透明效果色调图。

// mostly redundant calls, because they're all defaultself.edgesForExtendedLayout = UIRectEdgeAll;self.automaticallyAdjustsScrollViewInsets = YES;self.extendedLayoutIncludesOpaqueBars = NO;[[UINavigationBar appearance] setTintColor:[UIColor colorWithWhite:0.0 alpha:0.5]];
0 0
原创粉丝点击