-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSTCALayer.swift
More file actions
36 lines (31 loc) · 869 Bytes
/
Copy pathSTCALayer.swift
File metadata and controls
36 lines (31 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// STCALayer.swift
// STBaseProject
//
// Created by 寒江孤影 on 2019/1/21.
//
import QuartzCore
#if canImport(UIKit)
import UIKit
#endif
public extension CALayer {
/// 递归移除当前图层及所有子图层上的动画
/// 常用于在 reload/reset 前清理未结束的动画,避免视觉抖动
func removeAllAnimationsRecursively() {
CATransaction.begin()
removeAllAnimationsRecursivelyInner()
CATransaction.commit()
}
private func removeAllAnimationsRecursivelyInner() {
(sublayers ?? []).forEach { $0.removeAllAnimationsRecursivelyInner() }
removeAllAnimations()
}
}
#if canImport(UIKit)
public extension UIView {
/// 对视图树递归移除所有 CALayer 动画
func removeAllLayerAnimationsRecursively() {
layer.removeAllAnimationsRecursively()
}
}
#endif