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

Commit e48cc45

Browse files
authored
Animate the border as well to demonstrate that we can animate CALayer properties with the animator. (#101)
1 parent c04fd1a commit e48cc45

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

examples/TapToBounceTraitsExample.swift

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ class TapToBounceTraitsExampleViewController: UIViewController {
2929
circle.bounds = CGRect(x: 0, y: 0, width: 128, height: 128)
3030
circle.center = view.center
3131
circle.layer.cornerRadius = circle.bounds.width / 2
32+
circle.layer.borderColor = UIColor(red: (CGFloat)(0x88) / 255.0,
33+
green: (CGFloat)(0xEF) / 255.0,
34+
blue: (CGFloat)(0xAA) / 255.0,
35+
alpha: 1).cgColor
3236
circle.backgroundColor = UIColor(red: (CGFloat)(0xEF) / 255.0,
3337
green: (CGFloat)(0x88) / 255.0,
3438
blue: (CGFloat)(0xAA) / 255.0,
@@ -51,13 +55,18 @@ class TapToBounceTraitsExampleViewController: UIViewController {
5155
let animator = MotionAnimator()
5256
animator.animate(with: traits) {
5357
sender.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
58+
59+
// This would normally not be animatable with the UIView animation APIs, but it is animatable
60+
// with the motion animator.
61+
sender.layer.borderWidth = 10
5462
}
5563
}
5664

5765
func didUnfocus(_ sender: UIButton) {
5866
let animator = MotionAnimator()
5967
animator.animate(with: traits) {
6068
sender.transform = .identity
69+
sender.layer.borderWidth = 0
6170
}
6271
}
6372
}

examples/TapToBounceUIKitExample.swift

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class TapToBounceUIKitExampleViewController: UIViewController {
3030
circle.bounds = CGRect(x: 0, y: 0, width: 128, height: 128)
3131
circle.center = view.center
3232
circle.layer.cornerRadius = circle.bounds.width / 2
33+
circle.layer.borderColor = UIColor(red: (CGFloat)(0x88) / 255.0,
34+
green: (CGFloat)(0xEF) / 255.0,
35+
blue: (CGFloat)(0xAA) / 255.0,
36+
alpha: 1).cgColor
3337
circle.backgroundColor = UIColor(red: (CGFloat)(0xEF) / 255.0,
3438
green: (CGFloat)(0x88) / 255.0,
3539
blue: (CGFloat)(0xAA) / 255.0,
@@ -50,6 +54,10 @@ class TapToBounceUIKitExampleViewController: UIViewController {
5054
options: [],
5155
animations: {
5256
sender.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
57+
58+
// This would normally not be animatable with the UIView animation APIs, but it is animatable
59+
// with the motion animator.
60+
sender.layer.borderWidth = 10
5361
}, completion: nil)
5462
}
5563

@@ -61,6 +69,7 @@ class TapToBounceUIKitExampleViewController: UIViewController {
6169
options: [],
6270
animations: {
6371
sender.transform = .identity
72+
sender.layer.borderWidth = 0
6473
}, completion: nil)
6574
}
6675
}

0 commit comments

Comments
 (0)