ios – 如何制作一个褪色的导航栏

前端之家收集整理的这篇文章主要介绍了ios – 如何制作一个褪色的导航栏前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何制作淡出的导航栏?顶部的alpha值为0.5,下半部分为0.当它从上到下时,alpha减小,变得更透明.

像这样:

enter image description here

如您所见,当您沿着导航栏移动时,它变得更加透明.

解决方法

尝试使用CAGradientLayer来实现此目的.我测试过并且工作过.
对于Swift 3.0.

let gradient: CAGradientLayer = CAGradientLayer()

// put colors into an array,from top to bottom
gradient.colors = [UIColor.black.withAlphaComponent(0.5).cgColor,UIColor.clear.cgColor]
gradient.frame = view.frame

// setting direction and stop points - from top to bottom
gradient.startPoint = CGPoint(x: 0,y: 0)
gradient.endPoint = CGPoint(x: 0,y: 0.5)

yourView.layer.insertSublayer(gradient,at: 0)

猜你在找的Xcode相关文章