仿快手直播界面加載中,頂部的滾動條狀Loading,適用于 視頻加載動畫,直播界面加載動畫。基于CAReplicatorLayer實現,占用內存極小,非常輕量級
Screenshot 預覽圖
image
Installation 安裝
先在終端里搜索 pod search StripeAnimationLayer
如果搜索不到1.0.0版本,需要更新你電腦的pod倉庫,以下是更新步驟:
- 先
pod repo update —verbose
更新你本地電腦的pod倉庫。然后再搜索一次試試看 - 如果還是搜索不到,執行
rm ~/Library/Caches/CocoaPods/search_index.json
。再搜索就OK了
pod 'StripeAnimationLayer'
Example
Swift 調用方式:
override func viewDidLoad() {
super.viewDidLoad()
//傾斜layer; y值請一定設置為0;如果無需傾斜效果,那么width也無需乘以2
let animationLayer = StripeAnimationLayer(CGRect.init(x: 0, y: 0, width: self.view.frame.size.width * 2, height: self.view.bounds.height / 3), options: StripeLayerOptions())
self.view.layer.addSublayer(animationLayer);
}
OptionParams 可選參數:
/// 條紋顏色
/// Color of the shapes. Defaults to gray.
open var color = UIColor.lightGray
/// 如果不傾斜,那么gapWidth 和 barWidth相同比較好看,如果傾斜,建議gapWidth是barWidth的兩倍左右
/// Width of the bar
open var barWidth: CGFloat = 8
/// 間距寬度
/// Gap between bars
open var gapWidth: CGFloat = 8
/// 滾動方向
/// Direction
open var moveToRight: Bool = true
/// 滾動速度
/// Speed of the animation
open var speed: Float = 2
/// 傾斜角度, 3/4 = 45 度
/// Rotation of the shapes, 3/4 = 45 degree
open var rotation: CGFloat = CGFloat(Double.pi * 3.5 / 4)
/// 漸變透明度
/// Gradient alpha of the shapes.
open var gradientColors: [CGColor] = [UIColor(red: 0, green: 0, blue: 0, alpha: 0.3).cgColor, UIColor(red: 0, green: 0, blue: 0, alpha: 0).cgColor]
Github鏈接
求Star,后面還有更多好開源項目