diff --git a/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.h b/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.h index b3937f2f6a..e69e8a8716 100644 --- a/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.h +++ b/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.h @@ -20,4 +20,8 @@ toLayerNamed:(nonnull NSString *)layerName applyTransform:(BOOL)applyTransform; +- (CGRect)convertRect:(CGRect)rect + fromLayer:(CALayer *_Nonnull)fromlayer + toLayerNamed:(NSString *_Nonnull)layerName; + @end diff --git a/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.m b/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.m index a489f4ee98..e5520c2c6d 100644 --- a/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.m +++ b/lottie-ios/Classes/AnimatableLayers/LOTCompositionContainer.m @@ -137,6 +137,18 @@ } } +- (CGRect)convertRect:(CGRect)rect + fromLayer:(CALayer *_Nonnull)fromlayer + toLayerNamed:(NSString *_Nonnull)layerName { + CGRect xRect = rect; + for (LOTLayerContainer *child in _childLayers) { + if ([child.layerName isEqualToString:layerName]) { + xRect = [fromlayer convertRect:rect toLayer:child]; + } + } + return xRect; +} + - (void)setViewportBounds:(CGRect)viewportBounds { [super setViewportBounds:viewportBounds]; for (LOTLayerContainer *layer in _childLayers) { diff --git a/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.m b/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.m index bb4bc5e344..c5e75e13bc 100644 --- a/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.m +++ b/lottie-ios/Classes/AnimatableLayers/LOTLayerContainer.m @@ -15,7 +15,7 @@ #import "LOTMaskContainer.h" #import "LOTAsset.h" -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR #import "LOTCacheProvider.h" #endif @@ -121,7 +121,7 @@ [_wrapperLayer addSublayer:_contentsGroup.containerLayer]; } -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR - (void)_setImageForAsset:(LOTAsset *)asset { if (asset.imageName) { diff --git a/lottie-ios/Classes/MacCompatability/CALayer+Compat.h b/lottie-ios/Classes/MacCompatability/CALayer+Compat.h index ff17e638f0..ed50cd02a9 100644 --- a/lottie-ios/Classes/MacCompatability/CALayer+Compat.h +++ b/lottie-ios/Classes/MacCompatability/CALayer+Compat.h @@ -3,7 +3,7 @@ // Copyright (c) 2017 Airbnb. All rights reserved. // -#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR #import #import diff --git a/lottie-ios/Classes/MacCompatability/CALayer+Compat.m b/lottie-ios/Classes/MacCompatability/CALayer+Compat.m index c5cceb6b50..b856d2f521 100644 --- a/lottie-ios/Classes/MacCompatability/CALayer+Compat.m +++ b/lottie-ios/Classes/MacCompatability/CALayer+Compat.m @@ -3,7 +3,7 @@ // Copyright (c) 2017 Airbnb. All rights reserved. // -#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR #import "CALayer+Compat.h" @implementation CALayer (Compat) diff --git a/lottie-ios/Classes/MacCompatability/LOTPlatformCompat.h b/lottie-ios/Classes/MacCompatability/LOTPlatformCompat.h index d7a0f8a693..6a6a1e52e2 100644 --- a/lottie-ios/Classes/MacCompatability/LOTPlatformCompat.h +++ b/lottie-ios/Classes/MacCompatability/LOTPlatformCompat.h @@ -11,7 +11,7 @@ #import "TargetConditionals.h" -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR #import diff --git a/lottie-ios/Classes/MacCompatability/NSValue+Compat.h b/lottie-ios/Classes/MacCompatability/NSValue+Compat.h index e70eb2550a..fc0df3d747 100644 --- a/lottie-ios/Classes/MacCompatability/NSValue+Compat.h +++ b/lottie-ios/Classes/MacCompatability/NSValue+Compat.h @@ -3,7 +3,7 @@ // Copyright (c) 2017 Airbnb. All rights reserved. // -#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR #import @interface NSValue (Compat) diff --git a/lottie-ios/Classes/MacCompatability/NSValue+Compat.m b/lottie-ios/Classes/MacCompatability/NSValue+Compat.m index d5a3efe880..057e44605f 100644 --- a/lottie-ios/Classes/MacCompatability/NSValue+Compat.m +++ b/lottie-ios/Classes/MacCompatability/NSValue+Compat.m @@ -3,7 +3,7 @@ // Copyright (c) 2017 Airbnb. All rights reserved. // -#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR #import "NSValue+Compat.h" @implementation NSValue (Compat) diff --git a/lottie-ios/Classes/MacCompatability/UIColor.h b/lottie-ios/Classes/MacCompatability/UIColor.h index e1afb4f143..2b68c92478 100644 --- a/lottie-ios/Classes/MacCompatability/UIColor.h +++ b/lottie-ios/Classes/MacCompatability/UIColor.h @@ -6,7 +6,7 @@ // Copyright © 2017 Airbnb. All rights reserved. // -#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR #import #import diff --git a/lottie-ios/Classes/MacCompatability/UIColor.m b/lottie-ios/Classes/MacCompatability/UIColor.m index eca52a63ae..d3b9505ed2 100644 --- a/lottie-ios/Classes/MacCompatability/UIColor.m +++ b/lottie-ios/Classes/MacCompatability/UIColor.m @@ -6,7 +6,7 @@ // Copyright © 2017 Airbnb. All rights reserved. // -#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR +#if !TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR #import "UIColor.h" #import diff --git a/lottie-ios/Classes/Private/LOTAnimationTransitionController.m b/lottie-ios/Classes/Private/LOTAnimationTransitionController.m index 51bcd1323d..9235413eee 100644 --- a/lottie-ios/Classes/Private/LOTAnimationTransitionController.m +++ b/lottie-ios/Classes/Private/LOTAnimationTransitionController.m @@ -59,18 +59,19 @@ toSnapshot.frame = containerView.bounds; UIView *fromSnapshot = [fromVC.view resizableSnapshotViewFromRect:containerView.bounds - afterScreenUpdates:YES + afterScreenUpdates:NO withCapInsets:UIEdgeInsetsZero]; fromSnapshot.frame = containerView.bounds; tranistionAnimationView_.frame = containerView.bounds; tranistionAnimationView_.contentMode = UIViewContentModeScaleAspectFill; [containerView addSubview:tranistionAnimationView_]; - tranistionAnimationView_.animationProgress = 0; - [tranistionAnimationView_ layoutSubviews]; + BOOL crossFadeViews = NO; if (toLayerName_.length) { + CGRect convertedBounds = [tranistionAnimationView_ convertRect:containerView.bounds toLayerNamed:toLayerName_]; + toSnapshot.frame = convertedBounds; [tranistionAnimationView_ addSubview:toSnapshot toLayerNamed:toLayerName_ applyTransform:_applyTransform]; } else { [containerView addSubview:toSnapshot]; @@ -80,6 +81,8 @@ } if (fromLayerName_.length) { + CGRect convertedBounds = [tranistionAnimationView_ convertRect:containerView.bounds toLayerNamed:fromLayerName_]; + fromSnapshot.frame = convertedBounds; [tranistionAnimationView_ addSubview:fromSnapshot toLayerNamed:fromLayerName_ applyTransform:_applyTransform]; } else { [containerView addSubview:fromSnapshot]; diff --git a/lottie-ios/Classes/Private/LOTAnimationView.m b/lottie-ios/Classes/Private/LOTAnimationView.m index c6d962d639..a1448a7447 100644 --- a/lottie-ios/Classes/Private/LOTAnimationView.m +++ b/lottie-ios/Classes/Private/LOTAnimationView.m @@ -141,7 +141,7 @@ static NSString * const kCompContainerAnimationKey = @"play"; # pragma mark - Internal Methods -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR - (void)_initializeAnimationContainer { self.clipsToBounds = YES; @@ -417,11 +417,12 @@ static NSString * const kCompContainerAnimationKey = @"play"; # pragma mark - External Methods - Other -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR - (void)addSubview:(nonnull LOTView *)view toLayerNamed:(nonnull NSString *)layer applyTransform:(BOOL)applyTransform { + [self _layout]; CGRect viewRect = view.frame; LOTView *wrapperView = [[LOTView alloc] initWithFrame:viewRect]; view.frame = view.bounds; @@ -429,9 +430,6 @@ static NSString * const kCompContainerAnimationKey = @"play"; [wrapperView addSubview:view]; [self addSubview:wrapperView]; [_compContainer addSublayer:wrapperView.layer toLayerNamed:layer applyTransform:applyTransform]; - CGRect newRect = [self.layer convertRect:viewRect toLayer:wrapperView.layer.superlayer]; - wrapperView.layer.frame = newRect; - view.frame = newRect; } #else @@ -446,12 +444,18 @@ static NSString * const kCompContainerAnimationKey = @"play"; [wrapperView addSubview:view]; [self addSubview:wrapperView]; [_compContainer addSublayer:wrapperView.layer toLayerNamed:layer applyTransform:applyTransform]; - CGRect newRect = [self.layer convertRect:viewRect toLayer:wrapperView.layer.superlayer]; - wrapperView.layer.frame = newRect; - view.frame = newRect; } #endif + + +- (CGRect)convertRect:(CGRect)rect + toLayerNamed:(NSString *_Nonnull)layerName { + [self _layout]; + return [_compContainer convertRect:rect fromLayer:self.layer toLayerNamed:layerName]; +} + + - (void)setValue:(nonnull id)value forKeypath:(nonnull NSString *)keypath atFrame:(nullable NSNumber *)frame{ @@ -494,7 +498,7 @@ static NSString * const kCompContainerAnimationKey = @"play"; # pragma mark - Overrides -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR #define LOTViewContentMode UIViewContentMode #define LOTViewContentModeScaleToFill UIViewContentModeScaleToFill diff --git a/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h b/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h index ea88d37866..1eb96aea24 100644 --- a/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h +++ b/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h @@ -162,7 +162,18 @@ typedef void (^LOTAnimationCompletionBlock)(BOOL animationFinished); toLayerNamed:(nonnull NSString *)layer applyTransform:(BOOL)applyTransform; -#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR +/** + * Converts the given CGRect from the recieving animation view's coordinate space + * to the supplied layer's coordinate space + * + * This is helpful when adding custom subviews to a LOTAnimationView + * + **/ + +- (CGRect)convertRect:(CGRect)rect + toLayerNamed:(NSString *_Nonnull)layerName; + +#if !TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR @property (nonatomic) LOTViewContentMode contentMode; #endif diff --git a/lottie-ios/Classes/PublicHeaders/LOTAnimationView_Compat.h b/lottie-ios/Classes/PublicHeaders/LOTAnimationView_Compat.h index 9b28060bbb..20cf2e742f 100644 --- a/lottie-ios/Classes/PublicHeaders/LOTAnimationView_Compat.h +++ b/lottie-ios/Classes/PublicHeaders/LOTAnimationView_Compat.h @@ -6,7 +6,7 @@ // Copyright (c) 2017 Airbnb. All rights reserved. // -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR #import @compatibility_alias LOTView UIView; diff --git a/lottie-ios/Classes/PublicHeaders/LOTCacheProvider.h b/lottie-ios/Classes/PublicHeaders/LOTCacheProvider.h index de218f19e8..3857226f19 100644 --- a/lottie-ios/Classes/PublicHeaders/LOTCacheProvider.h +++ b/lottie-ios/Classes/PublicHeaders/LOTCacheProvider.h @@ -8,7 +8,7 @@ #import -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR #import @compatibility_alias LOTImage UIImage; diff --git a/lottie-ios/Classes/PublicHeaders/Lottie.h b/lottie-ios/Classes/PublicHeaders/Lottie.h index 3942634b68..297fbfec03 100644 --- a/lottie-ios/Classes/PublicHeaders/Lottie.h +++ b/lottie-ios/Classes/PublicHeaders/Lottie.h @@ -23,11 +23,11 @@ FOUNDATION_EXPORT const unsigned char LottieVersionString[]; #include -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR #import "LOTAnimationTransitionController.h" #endif -#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR +#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR #import "LOTCacheProvider.h" #endif