mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-18 03:20:09 +00:00
Revert some of the animationProgress changes to revert to reflect absolutes
- Update header documentation to make it clear how animatinoSpeed and animationProgress interact - Leave fixes in there that stop reversed animations "snapping" back
This commit is contained in:
parent
0896678088
commit
ab75236c5f
@ -210,27 +210,14 @@ static NSString * const kCompContainerAnimationKey = @"play";
|
||||
if (!_sceneModel) {
|
||||
return 0;
|
||||
}
|
||||
CGFloat absoluteProgress = ((frame.floatValue - _sceneModel.startFrame.floatValue) / (_sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue));
|
||||
if ([self _isPlayingForwards]) {
|
||||
return absoluteProgress;
|
||||
} else {
|
||||
// If the animation is playing backwards, the progress is inverted.
|
||||
return 1 - absoluteProgress;
|
||||
}
|
||||
return ((frame.floatValue - _sceneModel.startFrame.floatValue) / (_sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue));
|
||||
}
|
||||
|
||||
- (NSNumber *)_frameForProgress:(CGFloat)progress {
|
||||
if (!_sceneModel) {
|
||||
return @0;
|
||||
}
|
||||
CGFloat absoluteProgress = ((_sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue) * progress);
|
||||
if ([self _isPlayingForwards]) {
|
||||
// If we're moving forward, then add the absolute progress to the start.
|
||||
return @(absoluteProgress + _sceneModel.startFrame.floatValue);
|
||||
} else {
|
||||
// It the animation is playing backwards, subtract the progress from the end.
|
||||
return @(_sceneModel.endFrame.floatValue - absoluteProgress);
|
||||
}
|
||||
return @(((_sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue) * progress) + _sceneModel.startFrame.floatValue);
|
||||
}
|
||||
|
||||
- (BOOL)_isPlayingForwards {
|
||||
@ -397,18 +384,11 @@ static NSString * const kCompContainerAnimationKey = @"play";
|
||||
}
|
||||
|
||||
-(void)setAnimationSpeed:(CGFloat)animationSpeed {
|
||||
BOOL directionChange = NO;
|
||||
if ((animationSpeed >= 0 && _animationSpeed < 0) || (animationSpeed < 0 && _animationSpeed >= 0)) {
|
||||
directionChange = YES;
|
||||
}
|
||||
_animationSpeed = animationSpeed;
|
||||
NSNumber *frame = [_compContainer.presentationLayer.currentFrame copy];
|
||||
if (_isAnimationPlaying && _sceneModel) {
|
||||
NSNumber *frame = [_compContainer.presentationLayer.currentFrame copy];
|
||||
[self setProgressWithFrame:frame callCompletionIfNecessary:NO];
|
||||
[self playFromFrame:_playRangeStartFrame toFrame:_playRangeEndFrame withCompletion:self.completionBlock];
|
||||
} else if (directionChange) {
|
||||
// The progress needs to be re-calculated if the speed direction changes if the animation is not playing.
|
||||
_animationProgress = [self _progressForFrame:frame];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,12 @@ typedef void (^LOTAnimationCompletionBlock)(BOOL animationFinished);
|
||||
|
||||
// TODO
|
||||
/// Sets a progress from 0 - 1 of the animation. If the animation is playing it will stop and the compeltion block will be called.
|
||||
/// The animation progress is in terms of absolute progress of the defined animation and does not
|
||||
/// take into account negative speeds.
|
||||
@property (nonatomic, assign) CGFloat animationProgress;
|
||||
|
||||
/// Sets the speed of the animation. Accepts a negative value for reversing animation
|
||||
/// Sets the speed of the animation. Accepts a negative value for reversing animation.
|
||||
/// Negative speeds do not affect animationProgress
|
||||
@property (nonatomic, assign) CGFloat animationSpeed;
|
||||
|
||||
/// Read only of the duration in seconds of the animation at speed of 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user