1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- //
- // YLSingleText.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/3/11.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "YLSingleText.h"
- #define myRandomColor [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1]
- @interface YLSingleText ()
- {
- CGFloat _normalSteps;
- CGFloat _waveSteps;
- BOOL _directionChange;
- }
- @end
- @implementation YLSingleText
- + (instancetype)singleTextWithAnimationRange:(CGFloat)animationRange
- {
- YLSingleText *obj = [[self alloc] init];
- obj.animationRange = animationRange;
- return obj;
- }
- - (void)calculateStep
- {
- _directionChange ? _normalSteps-- : _normalSteps++;
-
- if (_normalSteps > self.animationRange) {
- _directionChange = YES;
- } else if (_normalSteps < 0) {
- _directionChange = NO;
- }
- }
- - (CGFloat)locationWithNormalAnimation
- {
- [self calculateStep];
- return _normalSteps;
- }
- - (CGFloat)locationWithFirstEnumerate
- {
- [self calculateStep];
- _normalSteps += 1;
- if (_normalSteps > self.animationRange) {
- _normalSteps = self.animationRange - (_normalSteps - self.animationRange);
- }
- self.enumerated = YES;
- return _normalSteps;
- }
- - (CGFloat)locationWithWaveAnimationCompletion:(void (^)(void))completion
- {
- _waveSteps++;
- if (_waveSteps > 2 * self.animationRange) {
- completion();
- return 0;
- }
- return [self locationWithNormalAnimation];
- }
- - (void)normalReset
- {
- self.enumerated = NO;
- _directionChange = NO;
- _normalSteps = 0;
- }
- - (void)waveReset
- {
- _waveSteps = 0;
- [self normalReset];
- }
- @end
|