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

Commit

Permalink
Animate the border as well to demonstrate that we can animate CALayer…
Browse files Browse the repository at this point in the history
… properties with the animator. (#101)
  • Loading branch information
jverkoey committed Dec 14, 2017
1 parent c04fd1a commit e48cc45
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions examples/TapToBounceTraitsExample.swift
Expand Up @@ -29,6 +29,10 @@ class TapToBounceTraitsExampleViewController: UIViewController {
circle.bounds = CGRect(x: 0, y: 0, width: 128, height: 128)
circle.center = view.center
circle.layer.cornerRadius = circle.bounds.width / 2
circle.layer.borderColor = UIColor(red: (CGFloat)(0x88) / 255.0,
green: (CGFloat)(0xEF) / 255.0,
blue: (CGFloat)(0xAA) / 255.0,
alpha: 1).cgColor
circle.backgroundColor = UIColor(red: (CGFloat)(0xEF) / 255.0,
green: (CGFloat)(0x88) / 255.0,
blue: (CGFloat)(0xAA) / 255.0,
Expand All @@ -51,13 +55,18 @@ class TapToBounceTraitsExampleViewController: UIViewController {
let animator = MotionAnimator()
animator.animate(with: traits) {
sender.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)

// This would normally not be animatable with the UIView animation APIs, but it is animatable
// with the motion animator.
sender.layer.borderWidth = 10
}
}

func didUnfocus(_ sender: UIButton) {
let animator = MotionAnimator()
animator.animate(with: traits) {
sender.transform = .identity
sender.layer.borderWidth = 0
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions examples/TapToBounceUIKitExample.swift
Expand Up @@ -30,6 +30,10 @@ class TapToBounceUIKitExampleViewController: UIViewController {
circle.bounds = CGRect(x: 0, y: 0, width: 128, height: 128)
circle.center = view.center
circle.layer.cornerRadius = circle.bounds.width / 2
circle.layer.borderColor = UIColor(red: (CGFloat)(0x88) / 255.0,
green: (CGFloat)(0xEF) / 255.0,
blue: (CGFloat)(0xAA) / 255.0,
alpha: 1).cgColor
circle.backgroundColor = UIColor(red: (CGFloat)(0xEF) / 255.0,
green: (CGFloat)(0x88) / 255.0,
blue: (CGFloat)(0xAA) / 255.0,
Expand All @@ -50,6 +54,10 @@ class TapToBounceUIKitExampleViewController: UIViewController {
options: [],
animations: {
sender.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)

// This would normally not be animatable with the UIView animation APIs, but it is animatable
// with the motion animator.
sender.layer.borderWidth = 10
}, completion: nil)
}

Expand All @@ -61,6 +69,7 @@ class TapToBounceUIKitExampleViewController: UIViewController {
options: [],
animations: {
sender.transform = .identity
sender.layer.borderWidth = 0
}, completion: nil)
}
}
Expand Down

0 comments on commit e48cc45

Please sign in to comment.