mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-25 13:31:22 +00:00
Setup for new animation state machine
This commit is contained in:
@@ -31,6 +31,11 @@
|
||||
// Currently Not Supported.
|
||||
@property (nonatomic, assign) BOOL autoReverseAnimation;
|
||||
|
||||
@property (nonatomic, assign) CFTimeInterval debugBeginTime;
|
||||
@property (nonatomic, assign) CFTimeInterval debugTimeOffset;
|
||||
@property (nonatomic, assign) CGFloat debugDuration;
|
||||
@property (nonatomic, assign) CGFloat debugSpeed;
|
||||
|
||||
- (void)playWithCompletion:(void (^)(void))completion;
|
||||
- (void)play;
|
||||
- (void)pause;
|
||||
|
||||
@@ -11,6 +11,16 @@
|
||||
#import "LAModels.h"
|
||||
#import "LAHelpers.h"
|
||||
|
||||
@interface LAAnimationState : NSObject
|
||||
|
||||
@property (nonatomic, assign) BOOL loopAnimation;
|
||||
@property (nonatomic, assign) BOOL animationIsPlaying;
|
||||
@property (nonatomic, assign) CFTimeInterval animationStartTime;
|
||||
@property (nonatomic, assign) CGFloat animatedProgress;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
|
||||
|
||||
@interface LAAnimationView ()
|
||||
@@ -46,7 +56,6 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
|
||||
_animationSpeed = 1;
|
||||
_animationContainer = [CALayer new];
|
||||
_animationContainer.frame = self.bounds;
|
||||
_animationContainer.speed = 0;
|
||||
_animationContainer.fillMode = kCAFillModeForwards;
|
||||
_animationContainer.masksToBounds = YES;
|
||||
[self.layer addSublayer:_animationContainer];
|
||||
@@ -54,6 +63,10 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
|
||||
self.clipsToBounds = YES;
|
||||
_timerLayer = [CALayer layer];
|
||||
[self.layer addSublayer:_timerLayer];
|
||||
_animationContainer.speed = 0.0;
|
||||
_animationContainer.beginTime = 0.0;
|
||||
_animationContainer.timeOffset = 0.0;
|
||||
_animationContainer.duration = self.sceneModel.timeDuration + singleFrameTimeValue;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -80,11 +93,22 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
|
||||
_layerMap = layerMap;
|
||||
}
|
||||
|
||||
- (void)play {
|
||||
[self playWithCompletion:nil];
|
||||
}
|
||||
|
||||
- (void)playWithCompletion:(void (^)(void))completion {
|
||||
// Problems with this method currently
|
||||
// If playing animation a second time, the animation is borked.
|
||||
|
||||
CFTimeInterval pausedTime = _animationContainer.timeOffset;
|
||||
_isAnimationPlaying = YES;
|
||||
_animationContainer.speed = self.animationSpeed;
|
||||
_animationContainer.duration = self.sceneModel.timeDuration + singleFrameTimeValue;
|
||||
_animationContainer.beginTime = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil];
|
||||
_animationContainer.timeOffset = 0.0;
|
||||
_animationContainer.beginTime = 0.0;
|
||||
CFTimeInterval timeSincePause = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
|
||||
_animationContainer.beginTime = timeSincePause;
|
||||
|
||||
|
||||
[CATransaction begin];
|
||||
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
|
||||
@@ -101,12 +125,18 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
|
||||
|
||||
}
|
||||
|
||||
- (void)play {
|
||||
[self playWithCompletion:nil];
|
||||
- (void)didMoveToSuperview {
|
||||
[super didMoveToSuperview];
|
||||
|
||||
}
|
||||
|
||||
- (void)pause {
|
||||
_animationContainer.speed = 0;
|
||||
CFTimeInterval pausedTime = [self.layer convertTime:CACurrentMediaTime() fromLayer:nil];
|
||||
_animationContainer.speed = 0.0;
|
||||
_animationContainer.beginTime = 0.0;
|
||||
_animationContainer.timeOffset = pausedTime;
|
||||
_isAnimationPlaying = NO;
|
||||
// TODO Fix completion block handling.
|
||||
}
|
||||
|
||||
- (void)setAnimationProgress:(CGFloat)animationProgress {
|
||||
@@ -122,6 +152,7 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
|
||||
- (void)setLoopAnimation:(BOOL)loopAnimation {
|
||||
_loopAnimation = loopAnimation;
|
||||
_animationContainer.repeatCount = loopAnimation ? HUGE_VALF : 0;
|
||||
_animationContainer.duration = loopAnimation ? self.sceneModel.timeDuration : 0;
|
||||
}
|
||||
|
||||
- (void)setAutoReverseAnimation:(BOOL)autoReverseAnimation {
|
||||
@@ -142,8 +173,6 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
|
||||
CGPoint centerPoint = CGRectGetCenterPoint(self.bounds);
|
||||
CATransform3D xform;
|
||||
|
||||
|
||||
|
||||
if (self.contentMode == UIViewContentModeScaleToFill) {
|
||||
CGSize scaleSize = CGSizeMake(self.bounds.size.width / self.sceneModel.compBounds.size.width,
|
||||
self.bounds.size.height / self.sceneModel.compBounds.size.height);
|
||||
@@ -174,6 +203,22 @@ const NSTimeInterval singleFrameTimeValue = 1.0 / 60.0;
|
||||
_animationContainer.transform = xform;
|
||||
_animationContainer.position = centerPoint;
|
||||
[CATransaction commit];
|
||||
|
||||
}
|
||||
|
||||
- (void)setDebugSpeed:(CGFloat)debugSpeed {
|
||||
_animationContainer.speed = debugSpeed;
|
||||
}
|
||||
|
||||
- (void)setDebugDuration:(CGFloat)debugDuration {
|
||||
_animationContainer.duration = debugDuration;
|
||||
}
|
||||
|
||||
- (void)setDebugBeginTime:(CFTimeInterval)debugBeginTime {
|
||||
_animationContainer.beginTime = debugBeginTime;
|
||||
}
|
||||
|
||||
- (void)setDebugTimeOffset:(CFTimeInterval)debugTimeOffset {
|
||||
_animationContainer.timeOffset = debugTimeOffset;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -13,5 +13,35 @@
|
||||
stopOnStyle = "0">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "No"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "Lotte/Lotte/LAAnimationView.m"
|
||||
timestampString = "501461136.579202"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "124"
|
||||
endingLineNumber = "124"
|
||||
landmarkName = "-playWithCompletion:"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
<BreakpointProxy
|
||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
||||
<BreakpointContent
|
||||
shouldBeEnabled = "Yes"
|
||||
ignoreCount = "0"
|
||||
continueAfterRunningActions = "No"
|
||||
filePath = "LotteExamples/LotteExamples/BBLotteExampleViewController.m"
|
||||
timestampString = "501203666.836893"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "167"
|
||||
endingLineNumber = "167">
|
||||
</BreakpointContent>
|
||||
</BreakpointProxy>
|
||||
</Breakpoints>
|
||||
</Bucket>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
#import <Lotte/Lotte.h>
|
||||
|
||||
@interface BBLotteExampleViewController ()
|
||||
@interface BBLotteExampleViewController () <UITextFieldDelegate>
|
||||
|
||||
@end
|
||||
|
||||
@@ -25,6 +25,32 @@
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
CGFloat xOrigin = 0;
|
||||
NSArray *strings = @[@"begin", @"offset", @"duration", @"speed"];
|
||||
CGFloat xDiv = self.view.bounds.size.width / strings.count;
|
||||
|
||||
|
||||
for (int i = 0; i < strings.count; i ++) {
|
||||
CGRect textFieldFrame = CGRectMake(xOrigin, 20, xDiv, 60);
|
||||
UITextField *inputField = [[UITextField alloc] initWithFrame:textFieldFrame];
|
||||
inputField.tag = i;
|
||||
inputField.delegate = self;
|
||||
inputField.placeholder = strings[i];
|
||||
[self.view addSubview:inputField];
|
||||
|
||||
textFieldFrame.origin.y += textFieldFrame.size.height;
|
||||
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[button setTitle:strings[i] forState:UIControlStateNormal];
|
||||
button.backgroundColor = [UIColor blueColor];
|
||||
button.frame = textFieldFrame;
|
||||
button.tag = i;
|
||||
[button addTarget:self action:@selector(setAnimationAttribute:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:button];
|
||||
xOrigin += xDiv;
|
||||
}
|
||||
|
||||
|
||||
openButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
||||
[openButton setTitle:@"Open" forState:UIControlStateNormal];
|
||||
[self.view addSubview:openButton];
|
||||
@@ -62,7 +88,7 @@
|
||||
CGRect sliderRect = CGRectMake(CGRectGetMaxX(loopButton.frame) + 10, CGRectGetMinY(loopButton.frame), boundsSize.width - CGRectGetMaxX(loopButton.frame) - 20, 44);
|
||||
animationSlider.frame = sliderRect;
|
||||
|
||||
currentAnimation.frame = CGRectMake(0, 0, boundsSize.width, boundsSize.height - 70);
|
||||
currentAnimation.frame = CGRectMake(0, 180, boundsSize.width, boundsSize.height - 250);
|
||||
|
||||
}
|
||||
|
||||
@@ -117,4 +143,49 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setAnimationAttribute:(UIButton *)button {
|
||||
// NSArray *strings = @[@"begin", @"offset", @"duration", @"speed"];
|
||||
switch (button.tag) {
|
||||
case 0: {
|
||||
currentAnimation.debugBeginTime = CACurrentMediaTime();
|
||||
} break;
|
||||
case 1: {
|
||||
currentAnimation.debugTimeOffset = CACurrentMediaTime();
|
||||
} break;
|
||||
case 2: {
|
||||
|
||||
} break;
|
||||
case 3: {
|
||||
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)textFieldDidEndEditing:(UITextField *)textField {
|
||||
switch (textField.tag) {
|
||||
case 0: {
|
||||
currentAnimation.debugBeginTime = textField.text.floatValue;
|
||||
} break;
|
||||
case 1: {
|
||||
currentAnimation.debugTimeOffset = textField.text.floatValue;
|
||||
|
||||
} break;
|
||||
case 2: {
|
||||
currentAnimation.debugDuration = textField.text.floatValue;
|
||||
} break;
|
||||
case 3: {
|
||||
currentAnimation.debugSpeed = textField.text.floatValue;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// timeOffset
|
||||
// beginTime
|
||||
// duration
|
||||
// speed
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user