恢复默认导航栏外观 [英] Restore default navigation bar appearance

查看:142
本文介绍了恢复默认导航栏外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm making an iOS app for iPhone, and I'm using a navigation controller. At some point during the navigation, I'm adding a UISegmentedControl to a view controller, just under the navigation bar from the navigation controller. I'm inserting new background and shadow images in the navigation bar, to make the UISegmentedControl appear as part of the navigation bar. I do it like this:

    // 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

当我离开给定的视图控制器时,导航栏背景仍然会改变。

When I navigate away from that given view controller, the navigation bars background is still changed.

如何恢复导航栏外观?

或...

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

Is there another way embed the UISegmentedControl into an expanded navigation bar?

带有自定义背景和分段控制的导航栏图片如下:
以下的段控制

Image of navigation bar with custom background and Segmented Control below:

导航栏时,导航栏可以自定义:

When navigating back, the navigation bar cuntinues to be custom:

编辑:

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

In a view controller before i change the background images, i try to safe the standart image:

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
    }
}

两者<$ c在s之后,$ c> herp 和 derp nil 等,这个妈妈可以看到导航栏。怎么来?

Both herp and derp are nil after being set, dispite the navigationbar is visible at this momont. How come?

推荐答案

只需将背景图像和阴影图像设置为<$,就可以恢复默认外观c $ c> nil 。

You should be able to get the default appearance back just by setting the background image and shadow image to nil.

这篇关于恢复默认导航栏外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆