diff --git a/Lotte/Lotte/LAAnimationView.h b/Lotte/Lotte/LAAnimationView.h index 16e279639e..607f7d969b 100644 --- a/Lotte/Lotte/LAAnimationView.h +++ b/Lotte/Lotte/LAAnimationView.h @@ -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; diff --git a/Lotte/Lotte/LAAnimationView.m b/Lotte/Lotte/LAAnimationView.m index bdaf1d7a1d..ba1c536192 100644 --- a/Lotte/Lotte/LAAnimationView.m +++ b/Lotte/Lotte/LAAnimationView.m @@ -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 diff --git a/LotteExamples.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/LotteExamples.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index e2573a5943..f7cedbf8dc 100644 --- a/LotteExamples.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/LotteExamples.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -13,5 +13,35 @@ stopOnStyle = "0"> + + + + + + + + diff --git a/LotteExamples/LotteExamples/BBLotteExampleViewController.m b/LotteExamples/LotteExamples/BBLotteExampleViewController.m index a07565d4bc..0f25afac92 100644 --- a/LotteExamples/LotteExamples/BBLotteExampleViewController.m +++ b/LotteExamples/LotteExamples/BBLotteExampleViewController.m @@ -11,7 +11,7 @@ #import -@interface BBLotteExampleViewController () +@interface BBLotteExampleViewController () @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