Video avatar fixes

This commit is contained in:
Ilya Laktyushin 2020-07-02 16:56:44 +03:00
parent f972dde0c9
commit 6e7d0c937d
5 changed files with 40 additions and 37 deletions

View File

@ -39,6 +39,8 @@
- (void)closeCurtains;
- (void)openCurtains;
- (void)flash:(void (^)(void))completion;
- (void)invalidateCropRect;
- (UIImage *)currentImage;

View File

@ -4,6 +4,7 @@
#import <ImageIO/ImageIO.h>
#import "TGMediaEditingContext.h"
#import "UIImage+TG.h"
@interface TGPaintFace ()

View File

@ -26,6 +26,8 @@ const CGFloat TGPhotoAvatarCropViewCurtainMargin = 200;
UIView *_snapshotView;
CGSize _snapshotSize;
UIView *_flashView;
UIView *_topOverlayView;
UIView *_leftOverlayView;
UIView *_rightOverlayView;
@ -82,6 +84,13 @@ const CGFloat TGPhotoAvatarCropViewCurtainMargin = 200;
_fullPreviewView.userInteractionEnabled = false;
[_wrapperView addSubview:_fullPreviewView];
_flashView = [[UIView alloc] init];
_flashView.alpha = 0.0;
_flashView.backgroundColor = [UIColor whiteColor];
_flashView.userInteractionEnabled = false;
[self addSubview:_flashView];
_topCurtainView = [[UIView alloc] initWithFrame:CGRectZero];
_topCurtainView.backgroundColor = [UIColor blackColor];
[self addSubview:_topCurtainView];
@ -611,6 +620,8 @@ const CGFloat TGPhotoAvatarCropViewCurtainMargin = 200;
{
[self _layoutOverlayViews];
_flashView.frame = self.bounds;
if (_scrollView.superview == nil)
{
_scrollView.frame = self.bounds;
@ -647,4 +658,16 @@ const CGFloat TGPhotoAvatarCropViewCurtainMargin = 200;
return CGSizeMake(20, 20);
}
- (void)flash:(void (^)(void))completion {
[UIView animateWithDuration:0.12 animations:^{
_flashView.alpha = 1.0f;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.2 animations:^{
_flashView.alpha = 0.0f;
} completion:^(BOOL finished) {
completion();
}];
}];
}
@end

View File

@ -42,8 +42,6 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel
TGMediaPickerGalleryVideoScrubber *_scrubberView;
UIView *_dotImageView;
UIView *_videoAreaView;
UIView *_flashView;
UIView *_portraitToolControlView;
UIView *_landscapeToolControlView;
UILabel *_coverLabel;
@ -162,18 +160,9 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel
_landscapeWrapperBackgroundView.backgroundColor = [TGPhotoEditorInterfaceAssets toolbarTransparentBackgroundColor];
_landscapeWrapperBackgroundView.userInteractionEnabled = false;
[_landscapeToolsWrapperView addSubview:_landscapeWrapperBackgroundView];
_videoAreaView = [[UIView alloc] init];
[self.view insertSubview:_videoAreaView belowSubview:_wrapperView];
[_portraitToolsWrapperView addSubview:_scrubberView];
_flashView = [[UIView alloc] init];
_flashView.alpha = 0.0;
_flashView.backgroundColor = [UIColor whiteColor];
_flashView.userInteractionEnabled = false;
[_videoAreaView addSubview:_flashView];
_coverLabel = [[UILabel alloc] init];
_coverLabel.alpha = 0.7f;
_coverLabel.backgroundColor = [UIColor clearColor];
@ -546,7 +535,6 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel
{
_portraitToolsWrapperView.alpha = 0.0f;
_landscapeToolsWrapperView.alpha = 0.0f;
_videoAreaView.alpha = 0.0f;
_dotImageView.alpha = 0.0f;
} completion:nil];
}
@ -737,12 +725,6 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel
CGRect containerFrame = [TGPhotoAvatarPreviewController photoContainerFrameForParentViewFrame:CGRectMake(0, 0, referenceSize.width, referenceSize.height) toolbarLandscapeSize:self.toolbarLandscapeSize orientation:self.effectiveOrientation panelSize:0 hasOnScreenNavigation:self.hasOnScreenNavigation];
CGSize fittedSize = TGScaleToSize(photoEditor.rotatedCropSize, containerFrame.size);
previewView.frame = CGRectMake(containerFrame.origin.x + (containerFrame.size.width - fittedSize.width) / 2, containerFrame.origin.y + (containerFrame.size.height - fittedSize.height) / 2, fittedSize.width, fittedSize.height);
[UIView performWithoutAnimation:^
{
_videoAreaView.frame = _previewView.frame;
_flashView.frame = _videoAreaView.bounds;
}];
}
- (void)updateLayout:(UIInterfaceOrientation)orientation
@ -828,29 +810,24 @@ const CGFloat TGPhotoAvatarPreviewLandscapePanelSize = TGPhotoAvatarPreviewPanel
- (void)beginScrubbing:(bool)flash
{
if (flash)
if (flash) {
_coverLabel.alpha = 1.0f;
}
}
- (void)endScrubbing:(bool)flash completion:(bool (^)(void))completion
{
if (flash) {
[UIView animateWithDuration:0.12 animations:^{
_flashView.alpha = 1.0f;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.2 animations:^{
_flashView.alpha = 0.0f;
} completion:^(BOOL finished) {
TGDispatchAfter(1.0, dispatch_get_main_queue(), ^{
if (completion()) {
[UIView animateWithDuration:0.2 animations:^{
_coverLabel.alpha = 0.7f;
}];
self.controlVideoPlayback(true);
}
});
}];
[_cropView flash:^{
TGDispatchAfter(1.0, dispatch_get_main_queue(), ^{
if (completion()) {
[UIView animateWithDuration:0.2 animations:^{
_coverLabel.alpha = 0.7f;
}];
self.controlVideoPlayback(true);
}
});
}];
} else {
TGDispatchAfter(1.32, dispatch_get_main_queue(), ^{

View File

@ -2591,7 +2591,7 @@
return !strongSelf->_scrubberView.isScrubbing;
}];
dispatch_async(dispatch_get_main_queue(), ^{
TGDispatchAfter(0.16, dispatch_get_main_queue(), ^{
[self updateDotImage:true];
});
}