如何将此效果淡入UINavigationBar?

时间:2017-04-11 02:37:18

标签: ios swift

func colorNavBarBackground(){ 
    if let user = self.user.data, let color = user.color1 {
        if let uiColor = UIColor(hexString: color) {
            self.navigationController?.navigationBar.setBackgroundImage(UIImage.colorForNavBar(uiColor), for: .default)
        }
        self.navigationController?.navigationBar.shadowImage = UIImage.colorForNavBar(COLORS.clear)
        self.navigationController?.navigationBar.tintColor  = COLORS.white
        self.navigationController?.navigationBar.titleTextAttributes = [
            NSForegroundColorAttributeName: COLORS.white,
            NSFontAttributeName: FONTS.navTitle
        ]
        UIApplication.shared.statusBarStyle = .lightContent
    }
}

理想情况下,我想淡化整个效果。但是,如果只有背景颜色可以淡入,那也没关系。

1 个答案:

答案 0 :(得分:0)

你可以使用它。

UIView.animateWithDuration(1.0, animations: { () -> Void in
   self.navigationController?.navigationBar.backgroundColor = UIColor.blackColor()
})