From d88a84e879bfa107d9c458a9fc30b36c5b60e945 Mon Sep 17 00:00:00 2001 From: Peter <> Date: Tue, 9 Jul 2019 19:42:51 +0400 Subject: [PATCH] Fix media recording UI --- .../TGModernConversationInputMicButton.m | 5 ++- .../TGVideoCameraGLRenderer.m | 25 ++++++++++- .../TGVideoMessageCaptureController.m | 43 ++++++++++++------- .../LegacyComponents/TGVideoMessageControls.m | 4 +- 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/submodules/LegacyComponents/LegacyComponents/TGModernConversationInputMicButton.m b/submodules/LegacyComponents/LegacyComponents/TGModernConversationInputMicButton.m index d9fb64a0f3..c9e97db366 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGModernConversationInputMicButton.m +++ b/submodules/LegacyComponents/LegacyComponents/TGModernConversationInputMicButton.m @@ -232,7 +232,10 @@ static const CGFloat outerCircleMinScale = innerCircleRadius / outerCircleRadius } UIView *parentView = [_presentation view]; - CGPoint centerPoint = [self.superview convertPoint:self.center toView:parentView]; + CGPoint centerPointInSelfWindow = [self.window convertPoint:self.center fromView:self.superview]; + CGPoint centerPointInParentViewWindow = [self.window convertPoint:centerPointInSelfWindow toWindow:parentView.window]; + CGPoint centerPoint = [parentView.window convertPoint:centerPointInParentViewWindow toView:parentView]; + centerPoint.x += _centerOffset.x; centerPoint.y += _centerOffset.y; _innerCircleView.center = centerPoint; diff --git a/submodules/LegacyComponents/LegacyComponents/TGVideoCameraGLRenderer.m b/submodules/LegacyComponents/LegacyComponents/TGVideoCameraGLRenderer.m index f96f2488e4..9ea032f1d4 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGVideoCameraGLRenderer.m +++ b/submodules/LegacyComponents/LegacyComponents/TGVideoCameraGLRenderer.m @@ -155,7 +155,30 @@ _textureVertices[7] = 0.0f; } break; - + case AVCaptureVideoOrientationPortraitUpsideDown: + if (!_mirror) + { + _textureVertices[0] = 1.0f - centerOffset; + _textureVertices[1] = 0.0f; + _textureVertices[2] = 1.0f - centerOffset; + _textureVertices[3] = 1.0f; + _textureVertices[4] = centerOffset; + _textureVertices[5] = 0.0f; + _textureVertices[6] = centerOffset; + _textureVertices[7] = 1.0f; + } + else + { + _textureVertices[0] = centerOffset; + _textureVertices[1] = 1.0f; + _textureVertices[2] = centerOffset; + _textureVertices[3] = 0.0f; + _textureVertices[4] = 1.0f - centerOffset; + _textureVertices[5] = 1.0f; + _textureVertices[6] = 1.0f - centerOffset; + _textureVertices[7] = 0.0f; + } + break; default: break; } diff --git a/submodules/LegacyComponents/LegacyComponents/TGVideoMessageCaptureController.m b/submodules/LegacyComponents/LegacyComponents/TGVideoMessageCaptureController.m index 5b537a9525..d95a4fd13b 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGVideoMessageCaptureController.m +++ b/submodules/LegacyComponents/LegacyComponents/TGVideoMessageCaptureController.m @@ -280,7 +280,14 @@ typedef enum [_wrapperView addSubview:_fadeView]; } - _circleWrapperView = [[UIView alloc] initWithFrame:CGRectMake((_wrapperView.frame.size.width - 216.0f - 38.0f) / 2.0f, _wrapperView.frame.size.height + 100.0f, 216.0f + 38.0f, 216.0f + 38.0f)]; + CGFloat circleWrapperViewLength = 216.0f + 38.0f; + _circleWrapperView = [[UIView alloc] initWithFrame:(CGRect){ + .origin.x = (_wrapperView.bounds.size.width - circleWrapperViewLength) / 2.0f, + .origin.y = _wrapperView.bounds.size.height + circleWrapperViewLength * 0.3f, + .size.width = circleWrapperViewLength, + .size.height = circleWrapperViewLength + }]; + _circleWrapperView.alpha = 0.0f; _circleWrapperView.clipsToBounds = false; [_wrapperView addSubview:_circleWrapperView]; @@ -305,14 +312,18 @@ typedef enum _placeholderView.accessibilityIgnoresInvertColors = true; } - _ringView = [[TGVideoMessageRingView alloc] initWithFrame:CGRectMake((_circleWrapperView.frame.size.width - 234.0f) / 2.0f, (_circleWrapperView.frame.size.height - 234.0f) / 2.0f, 234.0f, 234.0f)]; + CGFloat ringViewLength = 234.0f; + _ringView = [[TGVideoMessageRingView alloc] initWithFrame:(CGRect){ + .origin.x = (_circleWrapperView.bounds.size.width - ringViewLength) / 2.0f, + .origin.y = (_circleWrapperView.bounds.size.height - ringViewLength) / 2.0f, + .size.width = ringViewLength, + .size.height = ringViewLength + }]; _ringView.accentColor = self.pallete != nil ? self.pallete.buttonColor : TGAccentColor(); [_circleWrapperView addSubview:_ringView]; CGRect controlsFrame = _controlsFrame; - CGFloat height = TGIsPad() ? 56.0f : 45.0f; - controlsFrame.origin.y = CGRectGetMaxY(controlsFrame) - height; - controlsFrame.size.height = height; + controlsFrame.size.width = _wrapperView.frame.size.width; _controlsView = [[TGVideoMessageControls alloc] initWithFrame:controlsFrame assets:_assets]; _controlsView.pallete = self.pallete; @@ -357,7 +368,7 @@ typedef enum }; [self.view addSubview:_controlsView]; - _separatorView = [[UIView alloc] initWithFrame:CGRectMake(_controlsView.frame.origin.x, _controlsFrame.origin.y - TGScreenPixel, _controlsView.frame.size.width, TGScreenPixel)]; + _separatorView = [[UIView alloc] initWithFrame:CGRectMake(controlsFrame.origin.x, controlsFrame.origin.y - TGScreenPixel, controlsFrame.size.width, TGScreenPixel)]; _separatorView.backgroundColor = self.pallete != nil ? self.pallete.borderColor : UIColorRGB(0xb2b2b2); _separatorView.userInteractionEnabled = false; [self.view addSubview:_separatorView]; @@ -508,31 +519,33 @@ typedef enum _circleWrapperView.transform = CGAffineTransformMakeScale(0.3f, 0.3f); - CGPoint targetPosition = CGPointMake(_wrapperView.frame.size.width / 2.0f, _wrapperView.frame.size.height / 2.0f - _controlsView.frame.size.height); + CGPoint targetPosition = (CGPoint){ + .x = _wrapperView.frame.size.width / 2.0f, + .y = _wrapperView.frame.size.height / 2.0f - _controlsView.frame.size.height + }; switch (self.interfaceOrientation) { case UIInterfaceOrientationLandscapeLeft: - targetPosition.x = MIN(_wrapperView.frame.size.width - _circleWrapperView.bounds.size.width / 2.0f - 20.0f, _wrapperView.frame.size.width / 4.0f * 3.0f); - targetPosition.y = self.view.frame.size.height / 2.0f; break; - case UIInterfaceOrientationLandscapeRight: - targetPosition.x = MAX(_circleWrapperView.bounds.size.width / 2.0f + 20.0f, _wrapperView.frame.size.width / 4.0f); - targetPosition.y = self.view.frame.size.height / 2.0f; break; - default: if (self.view.frame.size.height > self.view.frame.size.width && fabs(_wrapperView.frame.size.height - self.view.frame.size.height) < 50.0f) targetPosition.y = _wrapperView.frame.size.height / 3.0f - 20.0f; targetPosition.y = MAX(_circleWrapperView.bounds.size.height / 2.0f + 40.0f, targetPosition.y); - break; } + if (TGIsPad()) { + _circleWrapperView.center = targetPosition; + } + [UIView animateWithDuration:0.5 delay:0.0 usingSpringWithDamping:0.8f initialSpringVelocity:0.2f options:kNilOptions animations:^ { - _circleWrapperView.center = targetPosition; + if (!TGIsPad()) { + _circleWrapperView.center = targetPosition; + } _circleWrapperView.transform = CGAffineTransformIdentity; } completion:nil]; diff --git a/submodules/LegacyComponents/LegacyComponents/TGVideoMessageControls.m b/submodules/LegacyComponents/LegacyComponents/TGVideoMessageControls.m index c595ba75a7..37d106cfb3 100644 --- a/submodules/LegacyComponents/LegacyComponents/TGVideoMessageControls.m +++ b/submodules/LegacyComponents/LegacyComponents/TGVideoMessageControls.m @@ -341,7 +341,7 @@ static CGRect viewFrame(UIView *view) { UIImage *deleteImage = _assets.actionDelete; - _deleteButton = [[TGModernButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 45.0f, 45.0f)]; + _deleteButton = [[TGModernButton alloc] initWithFrame:CGRectMake(0.0f, (self.bounds.size.height - 45.0f) / 2.0f, 45.0f, 45.0f)]; [_deleteButton setImage:deleteImage forState:UIControlStateNormal]; _deleteButton.adjustsImageWhenDisabled = false; _deleteButton.adjustsImageWhenHighlighted = false; @@ -491,7 +491,7 @@ static CGRect viewFrame(UIView *view) } setViewFrame(_sendButton, CGRectMake(self.frame.size.width - _sendButton.frame.size.width, 0.0f, _sendButton.frame.size.width, self.frame.size.height)); - _deleteButton.center = CGPointMake(24.0f, 22.0f); + _deleteButton.center = CGPointMake(24.0f, self.bounds.size.height / 2.0f); setViewFrame(_scrubberView, CGRectMake(46.0f, (self.frame.size.height - 33.0f) / 2.0f, self.frame.size.width - 46.0f * 2.0f, 33.0f)); }