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

UItableviewcell is visible back to navigation bar in ios

我正在使用下面的代码将渐变颜色设置为 navigationBar。但是在应用渐变颜色后,我的 table 视图单元格滚动回 navigationBar 并且顶部 cell 的内容有点可见回到 navigationBar.

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)

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