From d07c24be2e289927c8ea2e81fad6f97e3228813d Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 16 Jul 2020 23:17:32 +0300 Subject: [PATCH] Video avatar fixes --- .../Sources/TGPhotoEditorController.m | 7 ++++++- .../Sources/TGPhotoToolsController.m | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m index 7f7479dd3f..663157bd54 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoEditorController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoEditorController.m @@ -1178,13 +1178,18 @@ [self savePaintingData]; + bool resetTransform = false; + if ([self presentedForAvatarCreation] && tab == TGPhotoEditorCropTab && [currentController isKindOfClass:[TGPhotoPaintController class]]) { + resetTransform = true; + } + currentController.switchingToTab = tab; [currentController transitionOutSwitching:true completion:^ { [currentController removeFromParentViewController]; [currentController.view removeFromSuperview]; - if ([self presentedForAvatarCreation] && tab == TGPhotoEditorCropTab) { + if (resetTransform) { _previewView.transform = CGAffineTransformIdentity; } }]; diff --git a/submodules/LegacyComponents/Sources/TGPhotoToolsController.m b/submodules/LegacyComponents/Sources/TGPhotoToolsController.m index 8daf0740e6..8f0f0e9c0a 100644 --- a/submodules/LegacyComponents/Sources/TGPhotoToolsController.m +++ b/submodules/LegacyComponents/Sources/TGPhotoToolsController.m @@ -35,6 +35,7 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize bool _appeared; bool _scheduledTransitionIn; CGFloat _cellWidth; + int _entitiesReady; NSArray *_allTools; NSArray *_simpleTools; @@ -107,7 +108,12 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize } - (void)layoutEntitiesView { + if (_entitiesReady < 2 || _dismissing) + return; + + _entitiesWrapperView.transform = CGAffineTransformIdentity; _entitiesWrapperView.frame = CGRectMake(0.0, 0.0, _entitiesView.frame.size.width, _entitiesView.frame.size.height); + [_entitiesWrapperView addSubview:_entitiesView]; CGFloat paintingScale = _entitiesView.frame.size.width / _photoEditor.originalSize.width; _entitiesView.frame = CGRectMake(-_photoEditor.cropRect.origin.x * paintingScale, -_photoEditor.cropRect.origin.y * paintingScale, _entitiesView.frame.size.width, _entitiesView.frame.size.height); @@ -121,7 +127,8 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize CGFloat scale = _previewView.frame.size.width / _entitiesView.frame.size.width; _entitiesWrapperView.transform = CGAffineTransformMakeScale(scale * cropScale, scale * cropScale); - _entitiesWrapperView.frame = CGRectMake(0.0, 0.0, _previewView.frame.size.width, _previewView.frame.size.height); + + _entitiesWrapperView.frame = [_previewView convertRect:_previewView.bounds toView:_entitiesWrapperView.superview]; } - (void)loadView @@ -502,6 +509,9 @@ const CGFloat TGPhotoEditorToolsLandscapePanelSize = TGPhotoEditorToolsPanelSize TGPhotoEditorPreviewView *previewView = _previewView; previewView.hidden = false; [previewView performTransitionInIfNeeded]; + + _entitiesReady++; + [self layoutEntitiesView]; } - (void)prepareForCustomTransitionOut