CABasicAnimation的fillmode和isRemovedOnCompletion

CABasicAnimation 的 fillMode 定义了在动画active duration结束后的行为状态,

Determines if the receiver’s presentation is frozen or removed once its active duration has completed.

Defines how the timed object behaves outside its active duration.Local time may be clamped to either end of the active duration, or the element may be removed from the presentation. The legal values are backwards',forwards,both’ and removed. Defaults to removed.

在 Swift 4.2 以前 fillModel 的类型为 String

1
2
3
4
5
6
7
8
9
10
11
12
13
/* `fillMode' options. */

@available(iOS 2.0, *)
public let kCAFillModeForwards: String

@available(iOS 2.0, *)
public let kCAFillModeBackwards: String

@available(iOS 2.0, *)
public let kCAFillModeBoth: String

@available(iOS 2.0, *)
public let kCAFillModeRemoved: String

Swift 4.2 中 类型更改为 CAMediaTimingFillMode, 是一个 struct

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public struct CAMediaTimingFillMode : Hashable, Equatable, RawRepresentable {

public init(rawValue: String)
}

extension CAMediaTimingFillMode {


/* `fillMode' options. */

@available(iOS 2.0, *)
public static let forwards: CAMediaTimingFillMode


@available(iOS 2.0, *)
public static let backwards: CAMediaTimingFillMode


@available(iOS 2.0, *)
public static let both: CAMediaTimingFillMode


@available(iOS 2.0, *)
public static let removed: CAMediaTimingFillMode

此属性常常配合另一个属性isRemovedOnCompletion配合使用,两者的组合效果如下图: