Windless

Carthage compatible Version Xcode 9.0+ iOS 8.0+ Swift 4.0+ License

Windless 使你可以轻松地实现不可见的布局加载视图。

目录

需求

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理工具。你可以使用以下命令安装它

$ gem install cocoapods

构建 Windless 4.0+ 需要 CocoaPods 1.1+。

要使用 CocoaPods 将 Windless 集成到你的 Xcode 项目中,请在你的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Windless', '~> 0.1.5'
end

然后,运行以下命令

$ pod install

Carthage

Carthage 是一个去中心化的依赖管理工具,它可以构建你的依赖并为你提供二进制框架。

你可以使用 Homebrew 通过以下命令安装 Carthage

$ brew update
$ brew install carthage

要使用 Carthage 将 Windless 集成到你的 Xcode 项目中,请在你的 Cartfile 中指定它

github "Interactive-Studio/Windless" ~> 0.1.5

运行 carthage update 来构建框架,并将构建的 Windless.framework 拖到你的 Xcode 项目中。

手动

如果你不想使用上述任何一个依赖管理工具,你可以手动将 Windless 集成到你的项目中。


用法

代码

import Windless

class ViewController: UIViewController {

    lazy var contentsView = UIView()
    
    var subView1 = UIView()
    var subView2 = UIView()

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.addSubview(contentsView)
        contentsView.addSubview(subView1)
        contentsView.addSubview(subView2)
        
        // start
        contentsView.windless
                .setupWindlessableViews([subView1, subView2])
                .start()
                
        // stop
        contentsView.windless.end()
    }

}

Storyboard, Xib

如果你使用 Storyboardxib,你只需要将你想要显示为假视图的 isWindlessable 标志设置为 true,在视图检查器中,并且你不需要通过 setupWindlessableViews 方法传递视图。

import Windless

class ViewController: UIViewController {

    @IBOutlet weak var contentsView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        contentsView.windless.start()
    }
}

多行

根据 lineHeight 值和 spacing 值,UILabel 和 UITextView 将在 windless 动画运行时重建布局。

public protocol CanBeMultipleLines {

    var lineHeight: CGFloat { get set }

    var spacing: CGFloat { get set }
}
配置 结果

自定义选项

Windless 中有几个可自定义的选项。

public class WindlessConfiguration {
    
    /// The direction of windless animation. Defaults to rightDiagonal.
    public var direction: WindlessDirection = .rightDiagonal
    
    /// The speed of windless animation. Defaults to 1.
    public var speed: Float = 1
    
    /// The duration of the fade used when windless begins. Defaults to 0.
    public var beginTime: CFTimeInterval = 0
    
    /// The time interval windless in seconds. Defaults to 4.
    public var duration: CFTimeInterval = 4
    
    /// The time interval between windless in seconds. Defaults to 2.
    public var pauseDuration: CFTimeInterval = 2
    
    /// gradient animation timingFunction default easeOut
    public var timingFuction: CAMediaTimingFunction = .easeOut
    
    /// gradient layer center color default .lightGray
    public var animationLayerColor: UIColor = .lightGray
    
    /// Mask layer background color default .groupTableViewBackground
    public var animationBackgroundColor: UIColor = .groupTableViewBackground
    
    /// The opacity of the content while it is windless. Defaults to 0.8.
    public var animationLayerOpacity: CGFloat = 0.8
}

要设置这些选项,请使用如下所示的 apply 方法。

import Windless

class ViewController: UIViewController {

    @IBOutlet weak var contentsView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()

        contentsView.windless
            .apply {
                $0.beginTime = 1
                $0.pauseDuration = 2
                $0.duration = 3
                $0.animationLayerOpacity = 0.5
            }
            .start()
    }
}

如果你想了解更详细的用法,请参考 Example。

外观

isWindlessable 值决定了加载视图的外观。 下面的图片显示了根据 isWindlessable 值加载屏幕的外观。

isWindlessable= 🌀

配置 结果

交流

鸣谢

许可

Windless 在 MIT 许可证下发布。 有关详细信息,请参见 LICENSE。