Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 646b6f6

Browse files
authored
Add support for animating anchorPoint. (#97)
1 parent ca89662 commit 646b6f6

8 files changed

+21
-2
lines changed

src/MDMAnimatableKeyPaths.h

+10
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
NS_SWIFT_NAME(AnimatableKeyPath)
4343
typedef NSString * const MDMAnimatableKeyPath CF_TYPED_ENUM;
4444

45+
/**
46+
Anchor point.
47+
48+
Equivalent UIView property: N/A
49+
Equivalent CALayer property: anchorPoint
50+
Expected value type: CGPoint or NSValue (containing a CGPoint).
51+
Additive animation supported: No.
52+
*/
53+
FOUNDATION_EXPORT MDMAnimatableKeyPath MDMKeyPathAnchorPoint NS_SWIFT_NAME(anchorPoint);
54+
4555
/**
4656
Background color.
4757

src/MDMAnimatableKeyPaths.m

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#import "MDMAnimatableKeyPaths.h"
1818

19+
MDMAnimatableKeyPath MDMKeyPathAnchorPoint = @"anchorPoint";
1920
MDMAnimatableKeyPath MDMKeyPathBackgroundColor = @"backgroundColor";
2021
MDMAnimatableKeyPath MDMKeyPathBounds = @"bounds";
2122
MDMAnimatableKeyPath MDMKeyPathBorderWidth = @"borderWidth";

src/private/CABasicAnimation+MotionAnimator.m

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "CABasicAnimation+MotionAnimator.h"
1818

1919
#import "CAMediaTimingFunction+MotionAnimator.h"
20+
#import "MDMAnimatableKeyPaths.h"
2021

2122
#import <UIKit/UIKit.h>
2223

@@ -66,7 +67,9 @@ static BOOL IsAnimationKeyPathAlwaysNonAdditive(NSString *keyPath) {
6667
static NSSet *nonAdditiveKeyPaths = nil;
6768
static dispatch_once_t onceToken;
6869
dispatch_once(&onceToken, ^{
69-
nonAdditiveKeyPaths = [NSSet setWithArray:@[@"backgroundColor", @"opacity"]];
70+
nonAdditiveKeyPaths = [NSSet setWithArray:@[MDMKeyPathAnchorPoint,
71+
MDMKeyPathBackgroundColor,
72+
MDMKeyPathOpacity]];
7073
});
7174

7275
return [nonAdditiveKeyPaths containsObject:keyPath];

src/private/MDMBlockAnimations.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
static NSSet *animatableKeyPaths = nil;
2828
static dispatch_once_t onceToken;
2929
dispatch_once(&onceToken, ^{
30-
animatableKeyPaths = [NSSet setWithArray:@[MDMKeyPathBackgroundColor,
30+
animatableKeyPaths = [NSSet setWithArray:@[MDMKeyPathAnchorPoint,
31+
MDMKeyPathBackgroundColor,
3132
MDMKeyPathBorderWidth,
3233
MDMKeyPathBorderColor,
3334
MDMKeyPathBounds,

tests/unit/MotionAnimatorBehavioralTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class AnimatorBehavioralTests: XCTestCase {
4343
}
4444

4545
private let properties: [AnimatableKeyPath: Any] = [
46+
.anchorPoint: CGPoint(x: 0.2, y: 0.4),
4647
.backgroundColor: UIColor.blue,
4748
.borderWidth: 5,
4849
.borderColor: UIColor.red,

tests/unit/QuartzCoreBehavioralTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class QuartzCoreBehavioralTests: XCTestCase {
6969

7070
func testWhichPropertiesImplicitlyAnimateButNotAdditively() {
7171
let properties: [AnimatableKeyPath: Any] = [
72+
.anchorPoint: CGPoint(x: 0.2, y: 0.4),
7273
.borderWidth: 5,
7374
.borderColor: UIColor.red,
7475
.bounds: CGRect(x: 0, y: 0, width: 123, height: 456),

tests/unit/UIKitBehavioralTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class UIKitBehavioralTests: XCTestCase {
113113

114114
func testSomePropertiesImplicitlyAnimateButNotAdditively() {
115115
let baselineProperties: [AnimatableKeyPath: Any] = [
116+
.anchorPoint: CGPoint(x: 0.2, y: 0.4),
116117
.backgroundColor: UIColor.blue,
117118
.opacity: 0.5,
118119
]

tests/unit/UIKitEquivalencyTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class UIKitEquivalencyTests: XCTestCase {
100100

101101
func testSomePropertiesImplicitlyAnimateButNotAdditively() {
102102
let baselineProperties: [AnimatableKeyPath: Any] = [
103+
.anchorPoint: CGPoint(x: 0.2, y: 0.4),
103104
.backgroundColor: UIColor.blue,
104105
.borderColor: UIColor.red,
105106
.opacity: 0.5,

0 commit comments

Comments
 (0)