LOTShapeTransform.m 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // LOTShapeTransform.m
  3. // LottieAnimator
  4. //
  5. // Created by Brandon Withrow on 12/15/15.
  6. // Copyright © 2015 Brandon Withrow. All rights reserved.
  7. //
  8. #import "LOTShapeTransform.h"
  9. #import "LOTHelpers.h"
  10. @implementation LOTShapeTransform
  11. - (instancetype)initWithJSON:(NSDictionary *)jsonDictionary {
  12. self = [super init];
  13. if (self) {
  14. [self _mapFromJSON:jsonDictionary];
  15. }
  16. return self;
  17. }
  18. - (void)_mapFromJSON:(NSDictionary *)jsonDictionary {
  19. if (jsonDictionary[@"nm"] ) {
  20. _keyname = [jsonDictionary[@"nm"] copy];
  21. }
  22. NSDictionary *position = jsonDictionary[@"p"];
  23. if (position) {
  24. _position = [[LOTKeyframeGroup alloc] initWithData:position];
  25. }
  26. NSDictionary *anchor = jsonDictionary[@"a"];
  27. if (anchor) {
  28. _anchor = [[LOTKeyframeGroup alloc] initWithData:anchor];
  29. }
  30. NSDictionary *scale = jsonDictionary[@"s"];
  31. if (scale) {
  32. _scale = [[LOTKeyframeGroup alloc] initWithData:scale];
  33. [_scale remapKeyframesWithBlock:^CGFloat(CGFloat inValue) {
  34. return LOT_RemapValue(inValue, -100, 100, -1, 1);
  35. }];
  36. }
  37. NSDictionary *rotation = jsonDictionary[@"r"];
  38. if (rotation) {
  39. _rotation = [[LOTKeyframeGroup alloc] initWithData:rotation];
  40. [_rotation remapKeyframesWithBlock:^CGFloat(CGFloat inValue) {
  41. return LOT_DegreesToRadians(inValue);
  42. }];
  43. }
  44. NSDictionary *opacity = jsonDictionary[@"o"];
  45. if (opacity) {
  46. _opacity = [[LOTKeyframeGroup alloc] initWithData:opacity];
  47. [_opacity remapKeyframesWithBlock:^CGFloat(CGFloat inValue) {
  48. return LOT_RemapValue(inValue, 0, 100, 0, 1);
  49. }];
  50. }
  51. NSString *name = jsonDictionary[@"nm"];
  52. NSDictionary *skew = jsonDictionary[@"sk"];
  53. BOOL hasSkew = (skew && [skew[@"k"] isEqual:@0] == NO);
  54. NSDictionary *skewAxis = jsonDictionary[@"sa"];
  55. BOOL hasSkewAxis = (skewAxis && [skewAxis[@"k"] isEqual:@0] == NO);
  56. if (hasSkew || hasSkewAxis) {
  57. NSLog(@"%s: Warning: skew is not supported: %@", __PRETTY_FUNCTION__, name);
  58. }
  59. }
  60. - (NSString *)description {
  61. return [NSString stringWithFormat:@"LOTShapeTransform \"Position: %@ Anchor: %@ Scale: %@ Rotation: %@ Opacity: %@\"", _position.description, _anchor.description, _scale.description, _rotation.description, _opacity.description];
  62. }
  63. @end