Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.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/20.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/3/clojure/3.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_Uinavigationcontroller_Uinavigationbar - Fatal编程技术网

Ios 恢复默认导航栏外观

Ios 恢复默认导航栏外观,ios,swift,uinavigationcontroller,uinavigationbar,Ios,Swift,Uinavigationcontroller,Uinavigationbar,我正在为iPhone制作一个iOS应用程序,我正在使用一个导航控制器。在导航过程中的某个时刻,我将向视图控制器添加一个UISegmentedControl,就在导航控制器的导航栏下。我正在导航栏中插入新的背景和阴影图像,以使UISegmentedControl显示为导航栏的一部分。我是这样做的: // nav bar color image let rect = CGRectMake(0, 0, view.frame.width, 0.5) // Used in

我正在为iPhone制作一个iOS应用程序,我正在使用一个导航控制器。在导航过程中的某个时刻,我将向视图控制器添加一个
UISegmentedControl
,就在导航控制器的导航栏下。我正在导航栏中插入新的背景和阴影图像,以使
UISegmentedControl
显示为导航栏的一部分。我是这样做的:

    // nav bar color image
    let rect = CGRectMake(0, 0, view.frame.width, 0.5)          // Used in navBar, size dosn't matter
    UIGraphicsBeginImageContextWithOptions(rect.size, true, 0)
    barBackgroundColor.setFill()
    UIRectFill(rect)
    let navBarBackground = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    // setup navbar
    navigationController!.navigationBar.setBackgroundImage(navBarBackground, forBarMetrics: .Default)
    navigationController!.navigationBar.shadowImage = UIImage()
    navigationController!.navigationBar.tintColor = UIColor.blackColor()
    navigationController!.navigationBar.translucent = false
当我离开给定的视图控制器时,导航栏的背景仍然会改变

如何恢复导航栏的外观?

或者

是否有其他方法将
UISegmentedControl
嵌入到扩展的导航栏中?

具有自定义背景和分段控件的导航栏图像如下:

向后导航时,导航栏C将继续自定义:

编辑:

在视图控制器中,在更改背景图像之前,我尝试保护standart图像:

override func viewDidAppear(animated: Bool) {

    if sharedVariables.standartNavBarBackgroundImage == nil {
        let herp = navigationController!.navigationBar.backgroundImageForBarMetrics(.Default)
        sharedVariables.standartNavBarBackgroundImage = herp
        let derp = navigationController!.navigationBar.shadowImage
        sharedVariables.standartNavBarShadowImage = derp
    }
}

herp
derp
都是
nil
设置后,尽管导航栏在此位置可见。为什么呢?

在iOS 11.*和Swift 4中,只要将背景图像和阴影图像设置为
nil
,您就可以恢复默认外观。您需要将
BartinColor
设置为
nil

navigationController?.navigationBar.barTintColor = nil

显示您正在查找的最终结果的图片,以及如果您不更改添加的图像,它的外观。最终结果应为标准导航栏外观。如果以前未更改,则不显示。