Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS 7中的导航栏上获得模糊和半透明的效果? 问题_Ios_Cocoa Touch_Ios7_Uinavigationbar - Fatal编程技术网

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

如何在iOS 7中的导航栏上获得模糊和半透明的效果? 问题,ios,cocoa-touch,ios7,uinavigationbar,Ios,Cocoa Touch,Ios7,Uinavigationbar,我的应用程序似乎布局正确,但我无法实现iOS 7所著名的模糊半透明效果。我的看起来不透明 预期效果 我正在尝试获得更明显的模糊效果,比如苹果的预告片应用程序: 半透明性 在我的UINavigationController子类中,我将导航栏设置为半透明: - (id)initWithRootViewController:(UIViewController *)rootViewController { if (self = [super initWithRootViewControlle

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

预期效果 我正在尝试获得更明显的模糊效果,比如苹果的预告片应用程序:

半透明性 在我的UINavigationController子类中,我将导航栏设置为半透明:

- (id)initWithRootViewController:(UIViewController *)rootViewController
{
    if (self = [super initWithRootViewController:rootViewController]) {
        self.navigationBar.translucent = YES;
    }
    return self;
}
色调 在UIApplicationLegate的子类中,我设置了导航栏的色调。我发现色调的alpha值没有区别。也就是说,使用0.1的alpha不会使条形图变得更半透明

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    [[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
}
边缘 在我的内容视图控制器中,我将边缘设置为
UIRectEdgeNone
,这样顶部就不会通过导航栏。如果我使用默认的
UIRectEdgeAll
,导航栏将永久覆盖我的内容顶部。即使我生活在这种异常中,
UIRectEdgeAll
仍然无法启用半透明效果

- (void) viewDidLoad
{
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
}
// 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]];
编辑:尝试使用边 @rmaddy在评论中指出,问题可能出在edgesForExtendedLayout上。我找到了一个并尝试实现它:

- (void) viewDidLoad
{
    [super viewDidLoad];

    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.extendedLayoutIncludesOpaqueBars = NO;
}
它不起作用。首先,没有半透明效果。其次,我的内容顶部被砍掉了。在下面带有上述代码的示例页面上,头像最初由导航栏覆盖,很难滚动到。你可以向下拉以查看头像的顶部,但当你放开时,页面将自动反弹,头像将再次模糊


问题是由第三方下拉刷新视图引起的,在iOS 6引入系统刷新控制之前,该视图被广泛使用

这种观点混淆了iOS 7,使其认为内容比实际更高。对于iOS 6和iOS 7,我已经有条件地切换到使用。现在导航栏不会删除我的内容。我可以使用
UIRectEdgeAll
将我的内容放到导航栏下面。最后,我用较低的alpha为导航栏着色,以获得半透明效果

- (void) viewDidLoad
{
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
}
// 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]];

如果您需要获得与iTunes商店完全相同的效果(暗模糊)

按如下方式配置导航栏的
barStyle
属性:

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

你在测试什么设备?并非所有设备都显示模糊效果。并且不要使用
UIRectEdgeNone
。这就破坏了效果。仅当视图控制器位于导航栏下方时,效果才会出现。@rmaddy,屏幕截图出现在iOS 7.0.3的iPhone 5上,系统“减少动画”设置已关闭。使用默认的
UIRectEdgeAll
会使内容视图的顶部和底部卡在导航栏和选项卡栏下,正如我从中了解到的那样。我试过默认的
UIRectEdgeAll
,它对特效没有影响。你能改变Alpha值吗?