BlinkAnimationKit 是一个针对 iOS 的闪烁效果动画框架,使用 Swift 5 编写。应归功于原始作者 Shohei Yokoyama。这是他针对 Swift 5 更新过的库 ![]()
👀 示例
组件有 5 种动画类型。
边框
带阴影的边框
背景
波纹
文本
特性
-
类似于 blink 效果的
UIKit动画 -
5 种动画类型:
border、borderWithShadow、background、ripple、text -
易于使用
😝 -
在任意属性上可自定义动画
-
支持 Swift 5.0
🎉 -
支持
@IBDesignable和@IBInspectable。您可以在 Interface Builder 价格检查器 (IB) 中更改属性。然后 IB 会自动更新您的自定义对象。 -
兼容 Carthage
即将推出
- SYTextView
- SYImageView
示例应用
打开 Example/BlinkAnimationKit.xcworkspace 并运行 BlinkAnimationKit-Example 查看简单示例。
要运行示例项目,首先从示例目录运行 pod install
🔶 用法
首先在类中导入 SYBlinkAnimationKit。
import BlinkAnimationKitBlinkAnimationKit 被设计成易于使用。
- 调用 SYClass 例如,
SYButton、SYLabel、SYTextField等。 - 如果要使用自定义动画,请调用动画方法
startAnimating()、stopAnimating()
SYButton
let button = SYButton(frame: CGRect(x: 40, y: 50, width: 300, height: 50 ))
button.setTitle("Border Animation", forState: .normal)
button.animationType = .border
view.addSubview(button)
//Run Animation
syButton.startAnimating()
//End Animation
syButton.stopAnimating()文本动画
由于文本可操作,可用文本动画。
如果您更改文本字体大小、名称,应调用 `setFont()`。
button
.setFont(name: "ArialHebew", ofSize: 21)
.startAnimating()SYLabel
let label = SYLabel(frame: CGRect(x: 40, y: 50, width: 300, height: 50 ))
label.text = "Text Animation"
label.labelTextColor = .darkGray
label.animationType = .text
view.addSubview(label)文本动画
SYLabel 由于文本可操作,可用文本动画。
如果您设置文本颜色,应设置 labelTextColor 属性。要更改字体,使用与 SYButton 相同的字体方法。
label
.setFont(name: "ArialHebew", ofSize: 21)
.startAnimating()SYTableViewCell
继承 SYTableViewCell。在 UITableViewDataSource 中自定义您的 TableViewCell。
class YourCell: SYTableViewCell {
...func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("YourCell", forIndexPath: indexPath) as! YourCell
cell.animationType = .background
cell.startAnimating()
return cell
}SYCollectionViewCell
继承 SYCollectionViewCell。在 UICollectionViewDataSource 中自定义您的 CollectionViewCell。
class YourCell: SYCollectionViewCell {
...func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("YourCell", forIndexPath: indexPath) as! YourCell
cell.animationType = .background
cell.startAnimating()
return cell
}SYTextField
SYTextField 停止动画。当触摸时。但是你可以控制这种行为。
//The animation stop. when a touch. default is true
syTextField.stopAnimationWithTouch = true🔧 自定义动画属性
动画类型
如果你只想更改动画类型,可以自定义 animationType。
// default is border
var animationType: AnimationType
// Support 5 types of animation
enum AnimationType: Int {
case border
case borderWithShadow
case background
case ripple
case text
}inspectable
在 IB 中用 animationAdapter(整数)替换 animationType。
边框: 0带阴影的边框: 1背景: 2波纹: 3文本: 4
动画颜色
你可以自定义颜色属性。这些属性是 inspectable。
var animationBorderColor: UIColor var animationBackgroundColor: UIColor var animationTextColor: UIColor var animationRippleColor: UIColor动画持续时间和计时
你可以自定义 animationTimingFunction 和 animationDuration。
//default is linear
var animationTimingFunction: SYMediaTimingFunction
enum SYMediaTimingFunction: Int {
case linear
case easeIn
case easeOut
case easeInEaseOut
}
//default is 1.5
public var animationDuration: CGFloatinspectable
在 IB 中用 animationTimingAdapter(整数)替换 animationTimingFunction。
线性: 0加速进入: 1减速离开: 2加速进入或减速离开: 3
自定义动画文本
您可以为动画文本指定对齐方式。支持9种对齐方式。目前支持 SYButton 和 SYLabel。
var textAlignmentMode: TextAlignmentMode
enum TextAlignmentMode {
case topLeft, topCenter, topRight
case left, center, right
case bottomLeft, bottomCenter, bottomRight
}是否动画
如果 SYClass 正在进行动画,则该属性为 true
public var isAnimating: Bool💻 安装
CocoaPods
BlinkAnimationKit 可以通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中
pod "BlinkAnimationKit"📝 需求
- iOS 10.0+
- Xcode 10.0+
- Swift 5.0+
☕️ 作者
Isuru Ranasinghe,[email protected] ,Shohei Yokoyama,[email protected]
🔓 许可协议
BlinkAnimationKit 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件






