Various Fixes

This commit is contained in:
Ilya Laktyushin 2021-07-26 03:55:08 +03:00
parent e4f09f39fd
commit df7a68ea73
7 changed files with 131 additions and 11 deletions

View File

@ -60,7 +60,7 @@ typedef enum
@property (nonatomic, copy) void(^finishedModeChange)(void);
@property (nonatomic, copy) void(^beganPositionChange)(bool targetPositionHasFlash, bool targetPositionHasZoom, void(^commitBlock)(void));
@property (nonatomic, copy) void(^finishedPositionChange)(void);
@property (nonatomic, copy) void(^finishedPositionChange)(bool targetPositionHasZoom);
@property (nonatomic, copy) void(^beganAdjustingFocus)(void);
@property (nonatomic, copy) void(^finishedAdjustingFocus)(void);

View File

@ -18,6 +18,10 @@
@class TGMediaPickerGallerySelectedItemsModel;
@class TGMediaEditingContext;
@interface TGCameraCornersView : UIImageView
@end
@interface TGCameraMainView : UIView
{
UIInterfaceOrientation _interfaceOrientation;

View File

@ -690,7 +690,7 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus";
[strongSelf.captureSession setCurrentCameraPosition:targetCameraPosition];
if (strongSelf.finishedPositionChange != nil)
strongSelf.finishedPositionChange();
strongSelf.finishedPositionChange([PGCameraCaptureSession _isZoomAvailableForDevice:targetDevice]);
[strongSelf _subscribeForCameraChanges];
}];

View File

@ -107,6 +107,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
UIView *_backgroundView;
TGCameraPreviewView *_previewView;
TGCameraMainView *_interfaceView;
TGCameraCornersView *_cornersView;
UIView *_overlayView;
TGCameraFocusCrosshairsControl *_focusControl;
TGCameraRectangleView *_rectangleView;
@ -318,6 +319,9 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
_interfaceView.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(interfaceOrientation));
_interfaceView.frame = CGRectMake(0, 0, referenceSize.width, referenceSize.height);
}
_cornersView = [[TGCameraCornersView alloc] init];
if (_intent == TGCameraControllerPassportIdIntent)
[_interfaceView setDocumentFrameHidden:false];
_selectedItemsModel = [[TGMediaPickerGallerySelectedItemsModel alloc] initWithSelectionContext:nil items:[_items copy]];
@ -451,7 +455,8 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
}
[_autorotationCorrectionView addSubview:_interfaceView];
[_autorotationCorrectionView addSubview:_cornersView];
_photoSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
_photoSwipeGestureRecognizer.delegate = self;
[_autorotationCorrectionView addGestureRecognizer:_photoSwipeGestureRecognizer];
@ -633,7 +638,9 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
[strongSelf->_focusControl reset];
[strongSelf->_interfaceView setHasFlash:targetPositionHasFlash];
[strongSelf->_interfaceView setHasZoom:targetPositionHasZoom];
if (!targetPositionHasZoom) {
[strongSelf->_interfaceView setHasZoom:targetPositionHasZoom];
}
strongSelf->_camera.zoomLevel = 0.0f;
strongSelf.view.userInteractionEnabled = false;
@ -664,7 +671,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
}
};
_camera.finishedPositionChange = ^
_camera.finishedPositionChange = ^(bool targetPositionHasZoom)
{
__strong TGCameraController *strongSelf = weakSelf;
if (strongSelf == nil)
@ -675,6 +682,10 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
[strongSelf->_previewView endTransitionAnimated:true];
[strongSelf->_interfaceView setZoomLevel:1.0f displayNeeded:false];
if (targetPositionHasZoom) {
[strongSelf->_interfaceView setHasZoom:targetPositionHasZoom];
}
if (strongSelf->_camera.hasFlash && strongSelf->_camera.flashActive)
[strongSelf->_interfaceView setFlashActive:true];
@ -903,12 +914,22 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
animation.duration = 0.2f;
[_interfaceView.layer addAnimation:animation forKey:@"opacity"];
CABasicAnimation *cornersAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
cornersAnimation.fromValue = @(_cornersView.alpha);
cornersAnimation.toValue = @(hidden ? 0.0f : 1.0f);
cornersAnimation.duration = 0.2f;
[_cornersView.layer addAnimation:cornersAnimation forKey:@"opacity"];
_interfaceView.alpha = hidden ? 0.0f : 1.0f;
_cornersView.alpha = hidden ? 0.0 : 1.0;
}
else
{
[_interfaceView.layer removeAllAnimations];
_interfaceView.alpha = 0.0f;
_interfaceView.alpha = hidden ? 0.0 : 1.0;
[_cornersView.layer removeAllAnimations];
_cornersView.alpha = hidden ? 0.0 : 1.0;
}
}
@ -2155,6 +2176,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
[UIView animateWithDuration:0.3f delay:0.1f options:UIViewAnimationOptionCurveLinear animations:^
{
_interfaceView.alpha = 1.0f;
_cornersView.alpha = 1.0;
} completion:nil];
_interfaceView.previewViewFrame = _previewView.frame;
@ -2172,11 +2194,13 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
_backgroundView.alpha = 0.0f;
_interfaceView.alpha = 0.0f;
_cornersView.alpha = 0.0;
[UIView animateWithDuration:0.3f animations:^
{
_backgroundView.alpha = 1.0f;
_interfaceView.alpha = 1.0f;
_cornersView.alpha = 1.0;
}];
CGRect fromFrame = rect;
@ -2190,10 +2214,18 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
frameAnimation.springSpeed = 20;
frameAnimation.springBounciness = 1;
[_previewView pop_addAnimation:frameAnimation forKey:@"frame"];
POPSpringAnimation *cornersFrameAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
cornersFrameAnimation.fromValue = [NSValue valueWithCGRect:fromFrame];
cornersFrameAnimation.toValue = [NSValue valueWithCGRect:toFrame];
cornersFrameAnimation.springSpeed = 20;
cornersFrameAnimation.springBounciness = 1;
[_cornersView pop_addAnimation:cornersFrameAnimation forKey:@"frame"];
}
else
{
_previewView.frame = toFrame;
_cornersView.frame = toFrame;
}
_interfaceView.previewViewFrame = toFrame;
@ -2207,16 +2239,12 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
_focusControl.active = false;
_rectangleView.hidden = true;
[UIView animateWithDuration:0.3f animations:^
{
//[_context setApplicationStatusBarAlpha:1.0f];
}];
[self setInterfaceHidden:true animated:true];
[UIView animateWithDuration:0.25f animations:^
{
_backgroundView.alpha = 0.0f;
_cornersView.alpha = 0.0;
}];
CGRect referenceFrame = CGRectZero;
@ -2271,6 +2299,13 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
[strongSelf dismiss];
};
[_previewView pop_addAnimation:frameAnimation forKey:@"frame"];
POPSpringAnimation *cornersAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame];
cornersAnimation.fromValue = [NSValue valueWithCGRect:_cornersView.frame];
cornersAnimation.toValue = [NSValue valueWithCGRect:referenceFrame];
cornersAnimation.springSpeed = 20;
cornersAnimation.springBounciness = 1;
[_cornersView pop_addAnimation:cornersAnimation forKey:@"frame"];
}
else
{
@ -2327,6 +2362,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
[UIView animateWithDuration:ABS(distance / velocity) animations:^
{
_previewView.frame = targetFrame;
_cornersView.frame = targetFrame;
} completion:^(__unused BOOL finished)
{
if (completion)
@ -2343,11 +2379,13 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
[UIView animateWithDuration:0.3 animations:^
{
_previewView.frame = frame;
_cornersView.frame = frame;
}];
}
else
{
_previewView.frame = frame;
_cornersView.frame = frame;
}
}
@ -2389,6 +2427,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionLayoutSubviews animations:^
{
_previewView.frame = frame;
_cornersView.frame = frame;
_overlayView.frame = frame;
} completion:nil];
}

View File

@ -11,6 +11,8 @@
self = [super initWithFrame:frame];
if (self != nil)
{
self.adjustsImageWhenHighlighted = false;
self.modernHighlight = false;
self.exclusiveTouch = true;
self.backgroundColor = [TGCameraInterfaceAssets buttonColor];
self.layer.cornerRadius = 24.0;
@ -19,6 +21,16 @@
return self;
}
- (void)_setHighligtedAnimated:(bool)highlighted animated:(bool)animated {
if (animated) {
[UIView animateWithDuration:0.3 animations:^{
self.layer.sublayerTransform = highlighted ? CATransform3DMakeScale(0.9, 0.9, 1.0) : CATransform3DIdentity;
}];
} else {
self.layer.sublayerTransform = highlighted ? CATransform3DMakeScale(0.9, 0.9, 1.0) : CATransform3DIdentity;
}
}
- (void)setHidden:(BOOL)hidden
{
self.alpha = hidden ? 0.0f : 1.0f;
@ -60,6 +72,8 @@
self = [super initWithFrame:frame];
if (self != nil)
{
self.adjustsImageWhenHighlighted = false;
self.modernHighlight = false;
self.exclusiveTouch = true;
self.backgroundColor = [TGCameraInterfaceAssets buttonColor];
self.layer.cornerRadius = 24.0;
@ -68,6 +82,16 @@
return self;
}
- (void)_setHighligtedAnimated:(bool)highlighted animated:(bool)animated {
if (animated) {
[UIView animateWithDuration:0.3 animations:^{
self.layer.sublayerTransform = highlighted ? CATransform3DMakeScale(0.9, 0.9, 1.0) : CATransform3DIdentity;
}];
} else {
self.layer.sublayerTransform = highlighted ? CATransform3DMakeScale(0.9, 0.9, 1.0) : CATransform3DIdentity;
}
}
- (void)setHidden:(BOOL)hidden
{
self.alpha = hidden ? 0.0f : 1.0f;

View File

@ -14,6 +14,51 @@
#import "TGMediaPickerPhotoCounterButton.h"
#import "TGMediaPickerPhotoStripView.h"
@implementation TGCameraCornersView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self != nil) {
self.contentMode = UIViewContentModeScaleToFill;
static UIImage *cornersImage = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^
{
CGSize size = CGSizeMake(50.0, 50.0);
UIGraphicsBeginImageContextWithOptions(CGSizeMake(50.0, 50.0), false, 0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetAlpha(context, 0.5);
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextSetBlendMode(context, kCGBlendModeCopy);
CGFloat width = 1.0;
CGFloat length = 24.0;
CGContextFillRect(context, CGRectMake(0, 0, length, width));
CGContextFillRect(context, CGRectMake(0, 0, width, length));
CGContextFillRect(context, CGRectMake(size.width - length, 0, length, width));
CGContextFillRect(context, CGRectMake(size.width - width, 0, width, length));
CGContextFillRect(context, CGRectMake(0, size.height - width, length, width));
CGContextFillRect(context, CGRectMake(0, size.height - length, width, length));
CGContextFillRect(context, CGRectMake(size.width - length, size.height - width, length, width));
CGContextFillRect(context, CGRectMake(size.width - width, size.height - length, width, length));
cornersImage = [UIGraphicsGetImageFromCurrentImageContext() stretchableImageWithLeftCapWidth:25 topCapHeight:25];
UIGraphicsEndImageContext();
});
self.image = cornersImage;
self.userInteractionEnabled = false;
}
return self;
}
@end
@interface TGCameraMainView ()
{

View File

@ -66,12 +66,20 @@
[self reset];
_recordingTimer = [TGTimerTarget scheduledMainThreadTimerWithTarget:self action:@selector(recordingTimerEvent) interval:1.0 repeat:false];
[UIView animateWithDuration:0.2 animations:^{
_backgroundView.alpha = 1.0;
}];
}
- (void)stopRecording
{
[_recordingTimer invalidate];
_recordingTimer = nil;
[UIView animateWithDuration:0.2 animations:^{
_backgroundView.alpha = 0.0;
}];
}
- (void)reset