ios 导航栏

将导航栏设置为透明

1
2
3
4
5
6
   //背景设置为空
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
//去除横线
self.navigationController?.navigationBar.shadowImage = UIImage()
//设置为透明
self.navigationController?.navigationBar.isTranslucent = true

导航栏的颜色随着滚动条上翻渐渐从透明变成不透明
此时注意,一定需要将istranslucent设为true,不然不管怎么改alpha值,导航栏都会有背景色。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
func scrollViewDidScroll(_ scrollView: UIScrollView) {

let offset = scrollView.contentOffset.y
//大标题模式下的数值
if offset <= -88 {
naviAlpha = 0
} else if offset < -22 {
naviAlpha = (offset+88)/64
} else {
naviAlpha = 1
}
let image = UIImage.imageWithColor(Colors.naviBackground.withAlphaComponent(naviAlpha))
navigationController?.navigationBar.setBackgroundImage(image, for: .default)
}

Contents
,