ios - UItableviewcell 在 ios 中返回导航栏可见

标签 ios swift uitableview uinavigationbar gradient

我使用下面的代码将渐变颜色设置为navigationBar。但是在应用渐变颜色后,我的表格 View 单元格滚动回导航栏,并且顶部单元格的内容在导航栏上可见。

let gradient: CAGradientLayer = CAGradientLayer()
        let navigationBar = self.navigationController?.navigationBar.bounds
        let statusBar = UIApplication.sharedApplication().statusBarFrame
        let gradientBounds = CGRectMake(0.0, 0.0, (navigationBar?.size.width)!+statusBar.size.width, (navigationBar?.size.height)!+statusBar.size.height)
        gradient.frame = (gradientBounds)
        gradient.colors = [UIColor.redColor().CGColor, UIColor.blackColor().CGColor]
        gradient.locations = [0.0, 1.0]
        UIGraphicsBeginImageContext(gradient.bounds.size);
        gradient.renderInContext(UIGraphicsGetCurrentContext()!)
        let backImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        self.navigationController?.navigationBar.barStyle = UIBarStyle.Default
        self.navigationController?.navigationBar.setBackgroundImage(backImage, forBarMetrics: UIBarMetrics.Default)

enter image description here

最佳答案

导航栏默认是半透明的,即使不是,这仍然是第一个要验证的地方。设置纯色背景图像不会使其变得不透明,此外您还需要通过代码或在 Interface Builder 中设置导航栏 translucent 属性。

关于ios - UItableviewcell 在 ios 中返回导航栏可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34009365/

相关文章:

ios - 通过在两个图像之间滑动或点击来淡化图像

swift - 在 swift 中过滤数组文字时,为什么结果包含可选值?

iphone - 键盘隐藏自定义单元格

iphone - 分组 UITableView 中节标题和第一个单元格之间的透明像素行

ios - 一般问题,有什么建议吗?

iOS - 是否可以使用其展开操作方法中的代码中止展开转场?

ios - 如何从 WKWebView 获取服务器响应

ios - 增加 NSIndexPath

IOS:WKWebView中的文本选择(WKSelectionGranularityCharacter)

c# - 您可以从 iOS C 插件 "on the spot"写入 Unity 纹理吗?