省钱达人

TAAnimatedDotView.m 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // TAAnimatedDotView.m
  3. // TAPageControl
  4. //
  5. // Created by Tanguy Aladenise on 2015-01-22.
  6. // Copyright (c) 2015 Tanguy Aladenise. All rights reserved.
  7. //
  8. #import "TAAnimatedDotView.h"
  9. static CGFloat const kAnimateDuration = 1;
  10. @implementation TAAnimatedDotView
  11. - (instancetype)init
  12. {
  13. self = [super init];
  14. if (self) {
  15. [self initialization];
  16. }
  17. return self;
  18. }
  19. - (id)initWithFrame:(CGRect)frame
  20. {
  21. self = [super initWithFrame:frame];
  22. if (self) {
  23. [self initialization];
  24. }
  25. return self;
  26. }
  27. - (id)initWithCoder:(NSCoder *)aDecoder
  28. {
  29. self = [super initWithCoder:aDecoder];
  30. if (self) {
  31. [self initialization];
  32. }
  33. return self;
  34. }
  35. - (void)setDotColor:(UIColor *)dotColor
  36. {
  37. _dotColor = dotColor;
  38. self.layer.borderColor = dotColor.CGColor;
  39. }
  40. - (void)initialization
  41. {
  42. _dotColor = [UIColor whiteColor];
  43. self.backgroundColor = [UIColor clearColor];
  44. self.layer.cornerRadius = CGRectGetWidth(self.frame) / 2;
  45. self.layer.borderColor = [UIColor whiteColor].CGColor;
  46. self.layer.borderWidth = 2;
  47. }
  48. - (void)changeActivityState:(BOOL)active
  49. {
  50. if (active) {
  51. [self animateToActiveState];
  52. } else {
  53. [self animateToDeactiveState];
  54. }
  55. }
  56. - (void)animateToActiveState
  57. {
  58. [UIView animateWithDuration:kAnimateDuration delay:0 usingSpringWithDamping:.5 initialSpringVelocity:-20 options:UIViewAnimationOptionCurveLinear animations:^{
  59. self.backgroundColor = _dotColor;
  60. self.transform = CGAffineTransformMakeScale(1.4, 1.4);
  61. } completion:nil];
  62. }
  63. - (void)animateToDeactiveState
  64. {
  65. [UIView animateWithDuration:kAnimateDuration delay:0 usingSpringWithDamping:.5 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{
  66. self.backgroundColor = [UIColor clearColor];
  67. self.transform = CGAffineTransformIdentity;
  68. } completion:nil];
  69. }
  70. @end