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

Commit

Permalink
Add support for animating anchorPoint. (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
jverkoey committed Dec 14, 2017
1 parent ca89662 commit 646b6f6
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/MDMAnimatableKeyPaths.h
Expand Up @@ -42,6 +42,16 @@
NS_SWIFT_NAME(AnimatableKeyPath)
typedef NSString * const MDMAnimatableKeyPath CF_TYPED_ENUM;

/**
Anchor point.
Equivalent UIView property: N/A
Equivalent CALayer property: anchorPoint
Expected value type: CGPoint or NSValue (containing a CGPoint).
Additive animation supported: No.
*/
FOUNDATION_EXPORT MDMAnimatableKeyPath MDMKeyPathAnchorPoint NS_SWIFT_NAME(anchorPoint);

/**
Background color.
Expand Down
1 change: 1 addition & 0 deletions src/MDMAnimatableKeyPaths.m
Expand Up @@ -16,6 +16,7 @@

#import "MDMAnimatableKeyPaths.h"

MDMAnimatableKeyPath MDMKeyPathAnchorPoint = @"anchorPoint";
MDMAnimatableKeyPath MDMKeyPathBackgroundColor = @"backgroundColor";
MDMAnimatableKeyPath MDMKeyPathBounds = @"bounds";
MDMAnimatableKeyPath MDMKeyPathBorderWidth = @"borderWidth";
Expand Down
5 changes: 4 additions & 1 deletion src/private/CABasicAnimation+MotionAnimator.m
Expand Up @@ -17,6 +17,7 @@
#import "CABasicAnimation+MotionAnimator.h"

#import "CAMediaTimingFunction+MotionAnimator.h"
#import "MDMAnimatableKeyPaths.h"

#import <UIKit/UIKit.h>

Expand Down Expand Up @@ -66,7 +67,9 @@ static BOOL IsAnimationKeyPathAlwaysNonAdditive(NSString *keyPath) {
static NSSet *nonAdditiveKeyPaths = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
nonAdditiveKeyPaths = [NSSet setWithArray:@[@"backgroundColor", @"opacity"]];
nonAdditiveKeyPaths = [NSSet setWithArray:@[MDMKeyPathAnchorPoint,
MDMKeyPathBackgroundColor,
MDMKeyPathOpacity]];
});

return [nonAdditiveKeyPaths containsObject:keyPath];
Expand Down
3 changes: 2 additions & 1 deletion src/private/MDMBlockAnimations.m
Expand Up @@ -27,7 +27,8 @@
static NSSet *animatableKeyPaths = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
animatableKeyPaths = [NSSet setWithArray:@[MDMKeyPathBackgroundColor,
animatableKeyPaths = [NSSet setWithArray:@[MDMKeyPathAnchorPoint,
MDMKeyPathBackgroundColor,
MDMKeyPathBorderWidth,
MDMKeyPathBorderColor,
MDMKeyPathBounds,
Expand Down
1 change: 1 addition & 0 deletions tests/unit/MotionAnimatorBehavioralTests.swift
Expand Up @@ -43,6 +43,7 @@ class AnimatorBehavioralTests: XCTestCase {
}

private let properties: [AnimatableKeyPath: Any] = [
.anchorPoint: CGPoint(x: 0.2, y: 0.4),
.backgroundColor: UIColor.blue,
.borderWidth: 5,
.borderColor: UIColor.red,
Expand Down
1 change: 1 addition & 0 deletions tests/unit/QuartzCoreBehavioralTests.swift
Expand Up @@ -69,6 +69,7 @@ class QuartzCoreBehavioralTests: XCTestCase {

func testWhichPropertiesImplicitlyAnimateButNotAdditively() {
let properties: [AnimatableKeyPath: Any] = [
.anchorPoint: CGPoint(x: 0.2, y: 0.4),
.borderWidth: 5,
.borderColor: UIColor.red,
.bounds: CGRect(x: 0, y: 0, width: 123, height: 456),
Expand Down
1 change: 1 addition & 0 deletions tests/unit/UIKitBehavioralTests.swift
Expand Up @@ -113,6 +113,7 @@ class UIKitBehavioralTests: XCTestCase {

func testSomePropertiesImplicitlyAnimateButNotAdditively() {
let baselineProperties: [AnimatableKeyPath: Any] = [
.anchorPoint: CGPoint(x: 0.2, y: 0.4),
.backgroundColor: UIColor.blue,
.opacity: 0.5,
]
Expand Down
1 change: 1 addition & 0 deletions tests/unit/UIKitEquivalencyTests.swift
Expand Up @@ -100,6 +100,7 @@ class UIKitEquivalencyTests: XCTestCase {

func testSomePropertiesImplicitlyAnimateButNotAdditively() {
let baselineProperties: [AnimatableKeyPath: Any] = [
.anchorPoint: CGPoint(x: 0.2, y: 0.4),
.backgroundColor: UIColor.blue,
.borderColor: UIColor.red,
.opacity: 0.5,
Expand Down

0 comments on commit 646b6f6

Please sign in to comment.