1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- //
- // TAAnimatedDotView.m
- // TAPageControl
- //
- // Created by Tanguy Aladenise on 2015-01-22.
- // Copyright (c) 2015 Tanguy Aladenise. All rights reserved.
- //
- #import "TAAnimatedDotView.h"
- static CGFloat const kAnimateDuration = 1;
- @implementation TAAnimatedDotView
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- [self initialization];
- }
-
- return self;
- }
- - (id)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self initialization];
- }
- return self;
- }
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- self = [super initWithCoder:aDecoder];
- if (self) {
- [self initialization];
- }
-
- return self;
- }
- - (void)setDotColor:(UIColor *)dotColor
- {
- _dotColor = dotColor;
- self.layer.borderColor = dotColor.CGColor;
- }
- - (void)initialization
- {
- _dotColor = [UIColor whiteColor];
- self.backgroundColor = [UIColor clearColor];
- self.layer.cornerRadius = CGRectGetWidth(self.frame) / 2;
- self.layer.borderColor = [UIColor whiteColor].CGColor;
- self.layer.borderWidth = 2;
- }
- - (void)changeActivityState:(BOOL)active
- {
- if (active) {
- [self animateToActiveState];
- } else {
- [self animateToDeactiveState];
- }
- }
- - (void)animateToActiveState
- {
- [UIView animateWithDuration:kAnimateDuration delay:0 usingSpringWithDamping:.5 initialSpringVelocity:-20 options:UIViewAnimationOptionCurveLinear animations:^{
- self.backgroundColor = _dotColor;
- self.transform = CGAffineTransformMakeScale(1.4, 1.4);
- } completion:nil];
- }
- - (void)animateToDeactiveState
- {
- [UIView animateWithDuration:kAnimateDuration delay:0 usingSpringWithDamping:.5 initialSpringVelocity:0 options:UIViewAnimationOptionCurveLinear animations:^{
- self.backgroundColor = [UIColor clearColor];
- self.transform = CGAffineTransformIdentity;
- } completion:nil];
- }
- @end
|