NKSkeleton
界面
NKSkeleton
public class NKSkeleton {
public init(configuration: NKSkeletonConfiguration, sourceView: UIView? = nil)
/**
Show skeleton on `sourceView`
*/
public func show(on sourceView: UIView? = nil)
/**
Hide skeleton on `sourceView`
*/
public func remove()
}
NKSkeleton 配置
public struct NKSkeletonConfiguration {
/// The parameter indicates the need to play animation
public var isAnimatable = false
/// Sequence of colors to display the gradient
public var colors = [UIColor.white.cgColor, UIColor.lightGray.cgColor]
/// Gradient display type
public var type: NKType = .axial
/// The position of the beginning of the gradient vector
public var initialPosition: NKInitialPosition = .topLeft
/// The duration of one pass animation
public var duration: CFTimeInterval = 0
/// The level of subviews to be hidden by the skeleton, relative to the parent view
public var subviewsLevel = 0
public init()
}
public extension NKSkeletonConfiguration {
/// Skeleton gradient type
public enum NKType: Equatable {
/**
Using the parameter `.axial` gradient will be formed as a linear transition between the colors along the gradient vector
*/
case axial
/**
Using the parameter `.radial(Bool)` gradient will be formed as a radial transition between the colors from the starting point in all directions
The passed `Bool` parameter is responsible for the direction of the animation.
If `NKSkeletonConfiguration().isAnimatable = false` passed `Bool` parameter value will be ignored.
If passed `Bool` parameter is `true` animation will move from `NKSkeletonConfiguration().initialPosition' in all directions, else - from all directions to `NKSkeletonConfiguration().initialPosition'
*/
case radial(Bool)
}
/**
Starting (initial) point of the gradient on the `NKSkeleton().sourceView'
In case `NKSkeletonConfiguration().type = .axial' gradient vector will be directed from the selected starting point to the opposite side/corner
In case `NKSkeletonConfiguration().type = .radial(bool)' will be formed as a radial transition between the colors from the starting point in all directions
*/
public enum NKInitialPosition {
/// <if `NKSkeletonConfiguration().type = .axial'> from left side to right side
case left
/// <if `NKSkeletonConfiguration().type = .axial'> from right side to left side
case right
/// <if `NKSkeletonConfiguration().type = .axial'> from top side to bottom side
case top
/// <if `NKSkeletonConfiguration().type = .axial'> from bottom side to top side
case bottom
/// <if `NKSkeletonConfiguration().type = .axial'> from top left corner to bottom right corner
case topLeft
/// <if `NKSkeletonConfiguration().type = .axial'> from top right corner to bottom left corner
case topRight
/// <if `NKSkeletonConfiguration().type = .axial'> from bottom left corner to top right corner
case bottomLeft
/// <if `NKSkeletonConfiguration().type = .axial'> from bottom right corner to top left corner
case bottomRight
/// <if `NKSkeletonConfiguration().type = .axial'> from center to left and right sides
case center
}
}
以下图像展示了相对于主视图(《self.view》)确定子视图级别的原理。《a target="_blank" rel="noopener noreferrer" href="https://github.com/nkopilovskii/NKSkeleton/blob/master/Screenshots/levels.png?raw=true">
示例
要运行示例项目,首先克隆仓库,然后从 Example 目录运行 pod install
需求
安装
NKSkeleton 可通过 CocoaPods 获取。要安装,只需将以下行添加到您的 Podfile
pod 'NKSkeleton'
作者
nkopilovskii, [email protected]
许可协议
NKSkeleton 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件。