Android 条纹View、IOS 仿快手直播间Loading

2021-09-29  本文已影响0人  大鼓书

ios版本 Github链接

Android版本 Github链接

仿快手直播界面加载中,顶部的滚动条状Loading,适用于 视频加载动画,直播界面加载动画。基于CAReplicatorLayer实现,占用内存极小,非常轻量级

Screenshot 预览图

image

Installation 安装

先在终端里搜索 pod search StripeAnimationLayer

如果搜索不到1.0.0版本,需要更新你电脑的pod仓库,以下是更新步骤:

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,后面还有更多好开源项目

上一篇 下一篇

猜你喜欢

热点阅读