Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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中的模糊半透明导航栏_Ios_Swift_Cocoa_Navigation - Fatal编程技术网

iOS中的模糊半透明导航栏

iOS中的模糊半透明导航栏,ios,swift,cocoa,navigation,Ios,Swift,Cocoa,Navigation,我正在尝试在我的Swift iOS应用程序中获得这种模糊半透明导航栏效果(图像中的第一个导航栏): 但我做不到。我尝试了几种方法,其中一些方法如下: setBackgroundImage, shadowImage and translucent attrs in AppDelegate (Getting the NavController from the RootViewController attr) AppDelegate main方法中的这些行: UINavigationBar.ap

我正在尝试在我的Swift iOS应用程序中获得这种模糊半透明导航栏效果(图像中的第一个导航栏):

但我做不到。我尝试了几种方法,其中一些方法如下:

setBackgroundImage, shadowImage and translucent attrs in AppDelegate (Getting the NavController from the RootViewController attr)
AppDelegate main方法中的这些行:

UINavigationBar.appearance().translucent = true;
UINavigationBar.appearance().barTintColor = UIColor(white: 1, alpha: 0.4)
从UIBuilder更改属性

在ViewController中设置self.automaticallyAdjustsScrollViewInsets=true和self.edgesForExtendedLayout=uirectredge.None

但还是没法让它发挥作用。我使用iOS 8.1和9.0在XCode模拟器上运行该应用程序

我做错了什么?


也许更改plist可以解决您的问题。

第二个导航栏已经是半透明且模糊的,只是没有第一个导航栏那么透明。如果打开并将鼠标悬停在屏幕截图上,可以看到第二个导航栏的背景在覆盖图像的区域中较暗

第一个导航栏比第二个导航栏半透明的原因在中进行了解释:第一个导航栏的屏幕截图取自运行iOS 7.0.2的设备,而第二个导航栏的屏幕截图取自运行iOS 7.0.4的设备。苹果改变了iOS版本和iOS 7.1版本之间UINavigationBar的行为

苹果当前的半透明机制如下所示:

半透明条将其
BartinColor
与灰色混合,然后将其与系统定义的alpha值组合,以生成最终的背景色,用于将条与其覆盖的内容合成

模糊效果的唯一效果如下所示:

在iOS 7中,导航栏默认为半透明。此外,系统模糊应用于所有导航栏

您可以使用
UIImage.imageWithColor:
更改条形图的透明度,以从具有适当alpha值的UIColor生成条形图的背景图像,但这样做将消除模糊效果。没有记录在案的方法可以在不删除“系统模糊”的情况下更改“系统定义的alpha值”以增加条的半透明性

如果您想在iOS 8.1和9.0上模拟旧的半透明和模糊效果,您需要创建自己的UINavigationBar子类,并插入一个或多个子视图,例如具有使用适当alpha值(用于透明度)和/或UIVisualEffectView(用于模糊效果)的背景色的UIView

您可能可以在的一个答案中找到一个组合视图


相关:

didfishlaunchingwith选项中添加以下代码:

针对目标C

  [[UINavigationBar appearance] setTranslucent:NO];
适用于Swift 3+/iOS 10+

UINavigationBar.appearance().isTranslucent = false