mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Various Fixes
This commit is contained in:
parent
367836362a
commit
67ee626340
@ -86,6 +86,8 @@ typedef enum
|
||||
@property (nonatomic, readonly) CGFloat minZoomLevel;
|
||||
@property (nonatomic, readonly) CGFloat maxZoomLevel;
|
||||
|
||||
- (void)setZoomLevel:(CGFloat)zoomLevel animated:(bool)animated;
|
||||
|
||||
@property (nonatomic, readonly) bool hasUltrawideCamera;
|
||||
@property (nonatomic, readonly) bool hasTelephotoCamera;
|
||||
|
||||
|
@ -27,6 +27,8 @@
|
||||
@property (nonatomic, readonly) CGFloat minZoomLevel;
|
||||
@property (nonatomic, readonly) CGFloat maxZoomLevel;
|
||||
|
||||
- (void)setZoomLevel:(CGFloat)zoomLevel animated:(bool)animated;
|
||||
|
||||
@property (nonatomic, readonly) bool hasUltrawideCamera;
|
||||
@property (nonatomic, readonly) bool hasTelephotoCamera;
|
||||
|
||||
@ -34,9 +36,10 @@
|
||||
|
||||
@property (nonatomic, copy) void(^outputSampleBuffer)(CMSampleBufferRef sampleBuffer, AVCaptureConnection *connection);
|
||||
|
||||
@property (nonatomic, copy) void(^changingPosition)(void);
|
||||
@property (nonatomic, copy) bool(^requestPreviewIsMirrored)(void);
|
||||
|
||||
@property (nonatomic, copy) void(^crossfadeNeeded)(void);
|
||||
|
||||
@property (nonatomic, copy) void(^recognizedQRCode)(NSString *value, AVMetadataMachineReadableCodeObject *object);
|
||||
|
||||
@property (nonatomic, assign) bool compressVideo;
|
||||
|
@ -49,7 +49,7 @@
|
||||
|
||||
@property (nonatomic, copy) void(^focusPointChanged)(CGPoint point);
|
||||
@property (nonatomic, copy) void(^expositionChanged)(CGFloat value);
|
||||
@property (nonatomic, copy) void(^zoomChanged)(CGFloat level);
|
||||
@property (nonatomic, copy) void(^zoomChanged)(CGFloat level, bool animated);
|
||||
|
||||
@property (nonatomic, copy) void(^shutterPressed)(bool fromHardwareButton);
|
||||
@property (nonatomic, copy) void(^shutterReleased)(bool fromHardwareButton);
|
||||
@ -107,8 +107,6 @@
|
||||
- (UIInterfaceOrientation)interfaceOrientation;
|
||||
- (void)setInterfaceOrientation:(UIInterfaceOrientation)orientation animated:(bool)animated;
|
||||
|
||||
- (void)layoutPreviewRelativeViews;
|
||||
|
||||
- (void)photoCounterButtonPressed;
|
||||
|
||||
@end
|
||||
|
@ -18,7 +18,9 @@
|
||||
|
||||
@interface TGCameraZoomModeView : UIView
|
||||
|
||||
@property (copy, nonatomic) void(^zoomChanged)(CGFloat zoomLevel, bool done);
|
||||
@property (nonatomic, assign) UIInterfaceOrientation interfaceOrientation;
|
||||
|
||||
@property (copy, nonatomic) void(^zoomChanged)(CGFloat zoomLevel, bool done, bool animated);
|
||||
|
||||
@property (nonatomic, assign) CGFloat zoomLevel;
|
||||
- (void)setZoomLevel:(CGFloat)zoomLevel animated:(bool)animated;
|
||||
|
@ -692,7 +692,6 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus";
|
||||
if (strongSelf.finishedPositionChange != nil)
|
||||
strongSelf.finishedPositionChange();
|
||||
|
||||
[strongSelf setZoomLevel:0.0f];
|
||||
[strongSelf _subscribeForCameraChanges];
|
||||
}];
|
||||
};
|
||||
@ -733,12 +732,20 @@ NSString *const PGCameraAdjustingFocusKey = @"adjustingFocus";
|
||||
|
||||
- (void)setZoomLevel:(CGFloat)zoomLevel
|
||||
{
|
||||
[self setZoomLevel:zoomLevel animated:false];
|
||||
}
|
||||
|
||||
- (void)setZoomLevel:(CGFloat)zoomLevel animated:(bool)animated
|
||||
{
|
||||
if (self.cameraMode == PGCameraModeVideo) {
|
||||
animated = false;
|
||||
}
|
||||
[[PGCamera cameraQueue] dispatch:^
|
||||
{
|
||||
if (self.disabled)
|
||||
return;
|
||||
|
||||
[self.captureSession setZoomLevel:zoomLevel];
|
||||
[self.captureSession setZoomLevel:zoomLevel animated:animated];
|
||||
}];
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#import <SSignalKit/SSignalKit.h>
|
||||
|
||||
#import "POPSpringAnimation.h"
|
||||
|
||||
const NSInteger PGCameraFrameRate = 30;
|
||||
|
||||
@interface PGCameraCaptureSession () <AVCaptureVideoDataOutputSampleBufferDelegate, AVCaptureAudioDataOutputSampleBufferDelegate, AVCaptureMetadataOutputObjectsDelegate>
|
||||
@ -518,7 +520,11 @@ const NSInteger PGCameraFrameRate = 30;
|
||||
[self setZoomLevel:1.0];
|
||||
}
|
||||
|
||||
- (void)setZoomLevel:(CGFloat)zoomLevel
|
||||
- (void)setZoomLevel:(CGFloat)zoomLevel {
|
||||
[self setZoomLevel:zoomLevel animated:false];
|
||||
}
|
||||
|
||||
- (void)setZoomLevel:(CGFloat)zoomLevel animated:(bool)animated
|
||||
{
|
||||
if (![self.videoDevice respondsToSelector:@selector(setVideoZoomFactor:)])
|
||||
return;
|
||||
@ -554,7 +560,43 @@ const NSInteger PGCameraFrameRate = 30;
|
||||
}
|
||||
}
|
||||
}
|
||||
device.videoZoomFactor = MAX(1.0, MIN([strongSelf maxZoomLevel], backingLevel));
|
||||
CGFloat finalLevel = MAX(1.0, MIN([strongSelf maxZoomLevel], backingLevel));
|
||||
if (animated) {
|
||||
bool zoomingIn = finalLevel > self.videoDevice.videoZoomFactor;
|
||||
bool needsCrossfade = level >= 1.0;
|
||||
POPSpringAnimation *animation = [POPSpringAnimation new];
|
||||
animation.property = [POPAnimatableProperty propertyWithName:@"zoom" initializer:^(POPMutableAnimatableProperty *prop)
|
||||
{
|
||||
prop.readBlock = ^(PGCameraCaptureSession *session, CGFloat values[])
|
||||
{
|
||||
if (session != nil) {
|
||||
values[0] = session.videoDevice.videoZoomFactor;
|
||||
}
|
||||
};
|
||||
|
||||
prop.writeBlock = ^(PGCameraCaptureSession *session, const CGFloat values[])
|
||||
{
|
||||
if (session != nil) {
|
||||
if ((zoomingIn && values[0] > finalLevel - 0.015) || (!zoomingIn && values[0] < finalLevel + 0.015)) {
|
||||
if (needsCrossfade && session.crossfadeNeeded != nil)
|
||||
session.crossfadeNeeded();
|
||||
}
|
||||
[session _reconfigureDevice:session->_videoDevice withBlock:^(AVCaptureDevice *device) {
|
||||
device.videoZoomFactor = values[0];
|
||||
}];
|
||||
}
|
||||
};
|
||||
|
||||
prop.threshold = 0.03f;
|
||||
}];
|
||||
animation.fromValue = @(self.videoDevice.videoZoomFactor);
|
||||
animation.toValue = @(finalLevel);
|
||||
animation.springSpeed = 14;
|
||||
animation.springBounciness = 1;
|
||||
[self pop_addAnimation:animation forKey:@"zoom"];
|
||||
} else {
|
||||
device.videoZoomFactor = finalLevel;
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@ -759,9 +801,6 @@ const NSInteger PGCameraFrameRate = 30;
|
||||
[self _addAudioInputRequestAudioSession:false];
|
||||
}
|
||||
|
||||
if (self.changingPosition != nil)
|
||||
self.changingPosition();
|
||||
|
||||
[self commitConfiguration];
|
||||
|
||||
if (self.currentMode == PGCameraModeVideo || self.currentMode == PGCameraModeSquareVideo || self.currentMode == PGCameraModeSquareSwing)
|
||||
@ -771,6 +810,7 @@ const NSInteger PGCameraFrameRate = 30;
|
||||
}
|
||||
|
||||
_videoDevice = deviceForTargetPosition;
|
||||
[self resetZoom];
|
||||
|
||||
[self setCurrentFlashMode:self.currentFlashMode];
|
||||
|
||||
@ -959,51 +999,15 @@ const NSInteger PGCameraFrameRate = 30;
|
||||
|
||||
size_t width = CVPixelBufferGetWidth(imageBuffer);
|
||||
size_t height = CVPixelBufferGetHeight(imageBuffer);
|
||||
uint8_t *yBuffer = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0);
|
||||
size_t yPitch = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 0);
|
||||
uint8_t *cbCrBuffer = CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 1);
|
||||
size_t cbCrPitch = CVPixelBufferGetBytesPerRowOfPlane(imageBuffer, 1);
|
||||
|
||||
int bytesPerPixel = 4;
|
||||
uint8_t *rgbBuffer = malloc(width * height * bytesPerPixel);
|
||||
CIImage *coreImage = [CIImage imageWithCVPixelBuffer:imageBuffer];
|
||||
|
||||
for (size_t y = 0; y < height; y++)
|
||||
{
|
||||
uint8_t *rgbBufferLine = &rgbBuffer[y * width * bytesPerPixel];
|
||||
uint8_t *yBufferLine = &yBuffer[y * yPitch];
|
||||
uint8_t *cbCrBufferLine = &cbCrBuffer[(y >> 1) * cbCrPitch];
|
||||
|
||||
for (size_t x = 0; x < width; x++)
|
||||
{
|
||||
int16_t y = yBufferLine[x];
|
||||
int16_t cb = cbCrBufferLine[x & ~1] - 128;
|
||||
int16_t cr = cbCrBufferLine[x | 1] - 128;
|
||||
|
||||
uint8_t *rgbOutput = &rgbBufferLine[x * bytesPerPixel];
|
||||
|
||||
int16_t r = (int16_t)round( y + cr * 1.4 );
|
||||
int16_t g = (int16_t)round( y + cb * -0.343 + cr * -0.711 );
|
||||
int16_t b = (int16_t)round( y + cb * 1.765);
|
||||
|
||||
rgbOutput[0] = 0xff;
|
||||
rgbOutput[1] = clamp(b);
|
||||
rgbOutput[2] = clamp(g);
|
||||
rgbOutput[3] = clamp(r);
|
||||
}
|
||||
}
|
||||
|
||||
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
||||
CGContextRef context = CGBitmapContextCreate(rgbBuffer, width, height, 8, width * bytesPerPixel, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast);
|
||||
CGImageRef quartzImage = CGBitmapContextCreateImage(context);
|
||||
UIImage *image = [UIImage imageWithCGImage:quartzImage scale:1.0 orientation:orientation];
|
||||
|
||||
CGContextRelease(context);
|
||||
CGColorSpaceRelease(colorSpace);
|
||||
CIContext *ciContext = [CIContext contextWithOptions:nil];
|
||||
CGImageRef quartzImage = [ciContext createCGImage:coreImage fromRect:CGRectMake(0, 0, width, height)];
|
||||
UIImage *image = [[UIImage alloc] initWithCGImage:quartzImage scale:1.0 orientation:orientation];
|
||||
CGImageRelease(quartzImage);
|
||||
free(rgbBuffer);
|
||||
|
||||
CVPixelBufferUnlockBaseAddress(imageBuffer, 0);
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@ -1072,8 +1076,6 @@ static UIImageOrientation TGSnapshotOrientationForVideoOrientation(bool mirrored
|
||||
if (!self.isRunning || self.currentMode != PGCameraModePhoto)
|
||||
return;
|
||||
|
||||
|
||||
|
||||
if ([metadataObjects.firstObject isKindOfClass:[AVMetadataMachineReadableCodeObject class]])
|
||||
{
|
||||
AVMetadataMachineReadableCodeObject *object = (AVMetadataMachineReadableCodeObject *)metadataObjects.firstObject;
|
||||
|
@ -136,6 +136,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
|
||||
bool _saveCapturedMedia;
|
||||
|
||||
bool _shutterIsBusy;
|
||||
bool _crossfadingForZoom;
|
||||
|
||||
UIImpactFeedbackGenerator *_feedbackGenerator;
|
||||
|
||||
@ -378,13 +379,13 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
|
||||
[strongSelf->_camera setFlashMode:mode];
|
||||
};
|
||||
|
||||
_interfaceView.zoomChanged = ^(CGFloat level)
|
||||
_interfaceView.zoomChanged = ^(CGFloat level, bool animated)
|
||||
{
|
||||
__strong TGCameraController *strongSelf = weakSelf;
|
||||
if (strongSelf == nil)
|
||||
return;
|
||||
|
||||
[strongSelf->_camera setZoomLevel:level];
|
||||
[strongSelf->_camera setZoomLevel:level animated:animated];
|
||||
};
|
||||
|
||||
_interfaceView.shutterPressed = ^(bool fromHardwareButton)
|
||||
@ -655,6 +656,12 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
|
||||
}];
|
||||
});
|
||||
}];
|
||||
|
||||
if (iosMajorVersion() >= 13.0) {
|
||||
[strongSelf->_feedbackGenerator impactOccurredWithIntensity:0.5];
|
||||
} else {
|
||||
[strongSelf->_feedbackGenerator impactOccurred];
|
||||
}
|
||||
};
|
||||
|
||||
_camera.finishedPositionChange = ^
|
||||
@ -666,7 +673,7 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
|
||||
TGDispatchOnMainThread(^
|
||||
{
|
||||
[strongSelf->_previewView endTransitionAnimated:true];
|
||||
[strongSelf->_interfaceView setZoomLevel:0.0f displayNeeded:false];
|
||||
[strongSelf->_interfaceView setZoomLevel:1.0f displayNeeded:false];
|
||||
|
||||
if (strongSelf->_camera.hasFlash && strongSelf->_camera.flashActive)
|
||||
[strongSelf->_interfaceView setFlashActive:true];
|
||||
@ -770,6 +777,30 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_camera.captureSession.crossfadeNeeded = ^{
|
||||
__strong TGCameraController *strongSelf = weakSelf;
|
||||
if (strongSelf != nil)
|
||||
{
|
||||
if (strongSelf->_crossfadingForZoom) {
|
||||
return;
|
||||
}
|
||||
strongSelf->_crossfadingForZoom = true;
|
||||
|
||||
[strongSelf->_camera captureNextFrameCompletion:^(UIImage *image)
|
||||
{
|
||||
TGDispatchOnMainThread(^
|
||||
{
|
||||
[strongSelf->_previewView beginTransitionWithSnapshotImage:image animated:false];
|
||||
|
||||
TGDispatchAfter(0.05, dispatch_get_main_queue(), ^{
|
||||
[strongSelf->_previewView endTransitionAnimated:true];
|
||||
strongSelf->_crossfadingForZoom = false;
|
||||
});
|
||||
});
|
||||
}];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#pragma mark - View Life Cycle
|
||||
@ -2128,7 +2159,6 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
|
||||
} completion:nil];
|
||||
|
||||
_interfaceView.previewViewFrame = _previewView.frame;
|
||||
[_interfaceView layoutPreviewRelativeViews];
|
||||
|
||||
return targetFrame;
|
||||
}
|
||||
@ -2168,7 +2198,6 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
|
||||
}
|
||||
|
||||
_interfaceView.previewViewFrame = toFrame;
|
||||
[_interfaceView layoutPreviewRelativeViews];
|
||||
}
|
||||
|
||||
- (void)beginTransitionOutWithVelocity:(CGFloat)velocity
|
||||
@ -2356,7 +2385,6 @@ static CGPoint TGCameraControllerClampPointToScreenSize(__unused id self, __unus
|
||||
{
|
||||
CGRect frame = [TGCameraController _cameraPreviewFrameForScreenSize:TGScreenSize() mode:mode];
|
||||
_interfaceView.previewViewFrame = frame;
|
||||
[_interfaceView layoutPreviewRelativeViews];
|
||||
[_interfaceView updateForCameraModeChangeAfterResize];
|
||||
|
||||
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionLayoutSubviews animations:^
|
||||
|
@ -139,8 +139,6 @@ const CGFloat TGCameraFlashControlHeight = 44.0f;
|
||||
- (void)setInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||
{
|
||||
_interfaceOrientation = interfaceOrientation;
|
||||
|
||||
[self setActive:false animated:false];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -66,8 +66,6 @@
|
||||
TGCameraFlashControl *_flashControl;
|
||||
TGCameraFlashActiveView *_flashActiveView;
|
||||
|
||||
TGCameraFlipButton *_topFlipButton;
|
||||
|
||||
bool _hasResults;
|
||||
|
||||
CGFloat _topPanelOffset;
|
||||
@ -157,7 +155,7 @@
|
||||
else if (widescreenWidth >= 736.0f - FLT_EPSILON)
|
||||
{
|
||||
_topPanelHeight = 44.0f;
|
||||
_bottomPanelHeight = 140.0f;
|
||||
_bottomPanelHeight = 129.0f;
|
||||
_modeControlHeight = 50.0f;
|
||||
_counterOffset = 8.0f;
|
||||
shutterButtonWidth = 70.0f;
|
||||
@ -239,13 +237,8 @@
|
||||
_flashControl = [[TGCameraFlashControl alloc] initWithFrame:CGRectMake(3.0, 0, TGCameraFlashControlHeight, TGCameraFlashControlHeight)];
|
||||
[_topPanelView addSubview:_flashControl];
|
||||
|
||||
_topFlipButton = [[TGCameraFlipButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
|
||||
_topFlipButton.hidden = true;
|
||||
[_topFlipButton addTarget:self action:@selector(flipButtonPressed) forControlEvents:UIControlEventTouchUpInside];
|
||||
// [_topPanelView addSubview:_topFlipButton];
|
||||
|
||||
_timecodeView = [[TGCameraTimeCodeView alloc] initWithFrame:CGRectMake((frame.size.width - 120) / 2, 12, 120, 28)];
|
||||
_timecodeView.hidden = true;
|
||||
_timecodeView.alpha = 0.0;
|
||||
_timecodeView.requestedRecordingDuration = ^NSTimeInterval
|
||||
{
|
||||
__strong TGCameraMainPhoneView *strongSelf = weakSelf;
|
||||
@ -254,6 +247,7 @@
|
||||
|
||||
return strongSelf.requestedVideoRecordingDuration();
|
||||
};
|
||||
_timecodeView.userInteractionEnabled = false;
|
||||
[_topPanelView addSubview:_timecodeView];
|
||||
|
||||
_videoLandscapePanelView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 274, 44)];
|
||||
@ -263,29 +257,12 @@
|
||||
_videoLandscapePanelView.layer.cornerRadius = 3.5f;
|
||||
[self addSubview:_videoLandscapePanelView];
|
||||
|
||||
_flashActiveView = [[TGCameraFlashActiveView alloc] initWithFrame:CGRectMake((frame.size.width - 40) / 2, frame.size.height - _bottomPanelHeight - 37, 40, 21)];
|
||||
// [self addSubview:_flashActiveView];
|
||||
|
||||
_toastView = [[TGCameraToastView alloc] initWithFrame:CGRectMake(0, frame.size.height - _bottomPanelHeight - 42, frame.size.width, 32)];
|
||||
_toastView.userInteractionEnabled = false;
|
||||
[self addSubview:_toastView];
|
||||
|
||||
_zoomView = [[TGCameraZoomView alloc] initWithFrame:CGRectMake(10, frame.size.height - _bottomPanelHeight - _bottomPanelOffset - 18, frame.size.width - 20, 1.5f)];
|
||||
_zoomView.activityChanged = ^(bool active)
|
||||
{
|
||||
__strong TGCameraMainPhoneView *strongSelf = weakSelf;
|
||||
if (strongSelf == nil)
|
||||
return;
|
||||
|
||||
[UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^
|
||||
{
|
||||
[strongSelf _layoutFlashActiveViewForInterfaceOrientation:strongSelf->_interfaceOrientation zoomViewHidden:!active];
|
||||
} completion:nil];
|
||||
};
|
||||
// [self addSubview:_zoomView];
|
||||
|
||||
_zoomModeView = [[TGCameraZoomModeView alloc] initWithFrame:CGRectMake(floor((frame.size.width - 129.0) / 2.0), frame.size.height - _bottomPanelHeight - _bottomPanelOffset - 18 - 43, 129, 43) hasUltrawideCamera:hasUltrawideCamera hasTelephotoCamera:hasTelephotoCamera];
|
||||
_zoomModeView.zoomChanged = ^(CGFloat zoomLevel, bool done) {
|
||||
_zoomModeView.zoomChanged = ^(CGFloat zoomLevel, bool done, bool animated) {
|
||||
__strong TGCameraMainPhoneView *strongSelf = weakSelf;
|
||||
if (strongSelf == nil)
|
||||
return;
|
||||
@ -302,7 +279,7 @@
|
||||
}
|
||||
|
||||
if (strongSelf.zoomChanged != nil)
|
||||
strongSelf.zoomChanged(zoomLevel);
|
||||
strongSelf.zoomChanged(zoomLevel, animated);
|
||||
};
|
||||
[_zoomModeView setZoomLevel:1.0];
|
||||
[self addSubview:_zoomModeView];
|
||||
@ -390,15 +367,13 @@
|
||||
if (results.count == 0)
|
||||
{
|
||||
_hasResults = false;
|
||||
_topFlipButton.hidden = true;
|
||||
_flipButton.hidden = false;
|
||||
_doneButton.hidden = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_hasResults = true;
|
||||
_topFlipButton.hidden = _modeControl.cameraMode == PGCameraModePhotoScan;
|
||||
_flipButton.hidden = true;
|
||||
_flipButton.hidden = false;
|
||||
_doneButton.hidden = false;
|
||||
if (_modeControl.cameraMode == PGCameraModePhotoScan) {
|
||||
_modeControl.hidden = true;
|
||||
@ -479,11 +454,17 @@
|
||||
UIInterfaceOrientation orientation = _interfaceOrientation;
|
||||
PGCameraMode cameraMode = _modeControl.cameraMode;
|
||||
|
||||
if (UIInterfaceOrientationIsLandscape(orientation) && !((cameraMode == PGCameraModePhoto && previousMode == PGCameraModeSquarePhoto) || (cameraMode == PGCameraModeSquarePhoto && previousMode == PGCameraModePhoto)))
|
||||
[UIView animateWithDuration:0.25f delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^
|
||||
{
|
||||
if (cameraMode == PGCameraModeVideo)
|
||||
_timecodeView.hidden = true;
|
||||
|
||||
{
|
||||
_timecodeView.alpha = 1.0;
|
||||
} else {
|
||||
_timecodeView.alpha = 0.0;
|
||||
}
|
||||
} completion:nil];
|
||||
if (UIInterfaceOrientationIsLandscape(orientation) && !((cameraMode == PGCameraModePhoto && previousMode == PGCameraModeSquarePhoto) || (cameraMode == PGCameraModeSquarePhoto && previousMode == PGCameraModePhoto)))
|
||||
{
|
||||
[UIView animateWithDuration:0.25f delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^
|
||||
{
|
||||
_topPanelView.alpha = 0.0f;
|
||||
@ -492,7 +473,6 @@
|
||||
{
|
||||
if (cameraMode == PGCameraModeVideo)
|
||||
{
|
||||
_timecodeView.hidden = false;
|
||||
_flashControl.transform = CGAffineTransformIdentity;
|
||||
_flashControl.interfaceOrientation = UIInterfaceOrientationPortrait;
|
||||
[self _layoutTopPanelViewForInterfaceOrientation:orientation];
|
||||
@ -587,9 +567,8 @@
|
||||
_modeControl.hidden = false;
|
||||
_cancelButton.hidden = false;
|
||||
_flashControl.hidden = false;
|
||||
_flipButton.hidden = hasDoneButton;
|
||||
_flipButton.hidden = false;
|
||||
_bottomPanelBackgroundView.hidden = false;
|
||||
_topFlipButton.hidden = !hasDoneButton;
|
||||
}
|
||||
|
||||
[UIView animateWithDuration:0.25 animations:^
|
||||
@ -599,7 +578,6 @@
|
||||
_cancelButton.alpha = alpha;
|
||||
_flashControl.alpha = alpha;
|
||||
_flipButton.alpha = alpha;
|
||||
_topFlipButton.alpha = alpha;
|
||||
_bottomPanelBackgroundView.alpha = alpha;
|
||||
|
||||
if (hasDoneButton)
|
||||
@ -611,8 +589,7 @@
|
||||
_modeControl.hidden = hidden;
|
||||
_cancelButton.hidden = hidden;
|
||||
_flashControl.hidden = hidden;
|
||||
_flipButton.hidden = hidden || hasDoneButton;
|
||||
_topFlipButton.hidden = hidden || !hasDoneButton;
|
||||
_flipButton.hidden = hidden;
|
||||
_bottomPanelBackgroundView.hidden = hidden;
|
||||
|
||||
if (hasDoneButton)
|
||||
@ -631,10 +608,8 @@
|
||||
_cancelButton.alpha = alpha;
|
||||
_flashControl.hidden = hidden;
|
||||
_flashControl.alpha = alpha;
|
||||
_flipButton.hidden = hidden || hasDoneButton;
|
||||
_flipButton.hidden = hidden;
|
||||
_flipButton.alpha = alpha;
|
||||
_topFlipButton.hidden = hidden || !hasDoneButton;
|
||||
_topFlipButton.alpha = alpha;
|
||||
_bottomPanelBackgroundView.hidden = hidden;
|
||||
_bottomPanelBackgroundView.alpha = alpha;
|
||||
|
||||
@ -664,52 +639,31 @@
|
||||
{
|
||||
[UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^
|
||||
{
|
||||
_flashActiveView.alpha = 0.0f;
|
||||
|
||||
if (_modeControl.cameraMode == PGCameraModeVideo)
|
||||
{
|
||||
_topPanelView.alpha = 0.0f;
|
||||
_videoLandscapePanelView.alpha = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
_flashControl.alpha = 0.0f;
|
||||
}
|
||||
|
||||
_topFlipButton.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(orientation));
|
||||
_flipButton.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(orientation));
|
||||
_flashControl.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(orientation));
|
||||
_zoomModeView.interfaceOrientation = orientation;
|
||||
} completion:^(__unused BOOL finished)
|
||||
{
|
||||
[self _layoutFlashActiveViewForInterfaceOrientation:orientation zoomViewHidden:!_zoomView.isActive];
|
||||
|
||||
if (_modeControl.cameraMode == PGCameraModeVideo)
|
||||
{
|
||||
_flashControl.transform = CGAffineTransformIdentity;
|
||||
_flashControl.interfaceOrientation = UIInterfaceOrientationPortrait;
|
||||
|
||||
[self _layoutTopPanelViewForInterfaceOrientation:orientation];
|
||||
|
||||
if (UIInterfaceOrientationIsLandscape(orientation))
|
||||
[self _attachControlsToLandscapePanel];
|
||||
else
|
||||
[self _attachControlsToTopPanel];
|
||||
|
||||
_timecodeView.hidden = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_flashControl.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(orientation));
|
||||
_flashControl.interfaceOrientation = orientation;
|
||||
}
|
||||
|
||||
[self _layoutTopPanelSubviewsForInterfaceOrientation:orientation];
|
||||
|
||||
[_flashControl dismissAnimated:false];
|
||||
|
||||
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^
|
||||
{
|
||||
_flashActiveView.alpha = 1.0f;
|
||||
|
||||
if (_modeControl.cameraMode == PGCameraModeVideo)
|
||||
{
|
||||
if (UIInterfaceOrientationIsLandscape(orientation))
|
||||
@ -717,10 +671,6 @@
|
||||
else
|
||||
_topPanelView.alpha = 1.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
_flashControl.alpha = 1.0f;
|
||||
}
|
||||
} completion:nil];
|
||||
}];
|
||||
}
|
||||
@ -728,52 +678,11 @@
|
||||
{
|
||||
[_flashControl dismissAnimated:false];
|
||||
|
||||
_topFlipButton.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(orientation));
|
||||
_flipButton.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(orientation));
|
||||
_flashControl.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(orientation));
|
||||
_flashControl.interfaceOrientation = orientation;
|
||||
_zoomModeView.interfaceOrientation = orientation;
|
||||
|
||||
[self _layoutTopPanelSubviewsForInterfaceOrientation:orientation];
|
||||
|
||||
[self _layoutFlashActiveViewForInterfaceOrientation:orientation zoomViewHidden:!_zoomView.isActive];
|
||||
|
||||
if (_modeControl.cameraMode == PGCameraModeVideo)
|
||||
_timecodeView.hidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_layoutFlashActiveViewForInterfaceOrientation:(UIInterfaceOrientation)orientation zoomViewHidden:(bool)zoomViewHidden
|
||||
{
|
||||
CGFloat zoomOffset = 0;
|
||||
if (!zoomViewHidden)
|
||||
zoomOffset -= 23;
|
||||
|
||||
_flashActiveView.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(orientation));
|
||||
switch (orientation)
|
||||
{
|
||||
case UIInterfaceOrientationPortraitUpsideDown:
|
||||
{
|
||||
_flashActiveView.frame = CGRectMake((self.frame.size.width - 40) / 2, _topPanelHeight + 16, 40, 21);
|
||||
}
|
||||
break;
|
||||
|
||||
case UIInterfaceOrientationLandscapeLeft:
|
||||
{
|
||||
_flashActiveView.frame = CGRectMake(self.frame.size.width - 37, _topPanelHeight + (self.frame.size.height - _topPanelHeight - _bottomPanelHeight - _bottomPanelOffset - 40) / 2, 21, 40);
|
||||
}
|
||||
break;
|
||||
|
||||
case UIInterfaceOrientationLandscapeRight:
|
||||
{
|
||||
_flashActiveView.frame = CGRectMake(16, _topPanelHeight + (self.frame.size.height - _topPanelHeight - _bottomPanelHeight - _bottomPanelOffset - 40) / 2, 21, 40);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
_flashActiveView.frame = CGRectMake((self.frame.size.width - 40) / 2, self.frame.size.height - _bottomPanelHeight - _bottomPanelOffset - 37 + zoomOffset, 40, 21);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -826,13 +735,11 @@
|
||||
|
||||
- (void)_attachControlsToTopPanel
|
||||
{
|
||||
[_topPanelView addSubview:_flashControl];
|
||||
[_topPanelView addSubview:_timecodeView];
|
||||
}
|
||||
|
||||
- (void)_attachControlsToLandscapePanel
|
||||
{
|
||||
[_videoLandscapePanelView addSubview:_flashControl];
|
||||
[_videoLandscapePanelView addSubview:_timecodeView];
|
||||
}
|
||||
|
||||
@ -844,24 +751,9 @@
|
||||
if (superview == _videoLandscapePanelView && superviewSize.width < superviewSize.height)
|
||||
superviewSize = CGSizeMake(superviewSize.height, superviewSize.width);
|
||||
|
||||
// if (UIInterfaceOrientationIsLandscape(orientation) && _flashControl.interfaceOrientation == orientation && _flashControl.superview == _topPanelView)
|
||||
// {
|
||||
// if (orientation == UIInterfaceOrientationLandscapeLeft)
|
||||
// _flashControl.frame = CGRectMake(7, 0, TGCameraFlashControlHeight, 370);
|
||||
// else if (orientation == UIInterfaceOrientationLandscapeRight)
|
||||
// _flashControl.frame = CGRectMake(7, 0, TGCameraFlashControlHeight, 370);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// _flashControl.frame = CGRectMake(0, (superviewSize.height - TGCameraFlashControlHeight) / 2, superviewSize.width, TGCameraFlashControlHeight);
|
||||
// }
|
||||
_timecodeView.frame = CGRectMake((superviewSize.width - 120) / 2, (superviewSize.height - 28) / 2, 120, 28);
|
||||
}
|
||||
|
||||
- (void)layoutPreviewRelativeViews
|
||||
{
|
||||
}
|
||||
|
||||
- (void)layoutSubviews
|
||||
{
|
||||
_topPanelView.frame = CGRectMake(0, _topPanelOffset, self.frame.size.width, _topPanelHeight);
|
||||
@ -886,8 +778,6 @@
|
||||
|
||||
_flipButton.frame = CGRectMake(self.frame.size.width - _flipButton.frame.size.width - 20.0f, round(_shutterButton.center.y - _flipButton.frame.size.height / 2.0f), _flipButton.frame.size.width, _flipButton.frame.size.height);
|
||||
|
||||
_topFlipButton.frame = CGRectMake(self.frame.size.width - _topFlipButton.frame.size.width - 4.0f, 0.0f, _topFlipButton.frame.size.width, _topFlipButton.frame.size.height);
|
||||
|
||||
_toastView.frame = CGRectMake(0, self.frame.size.height - _bottomPanelHeight - _bottomPanelOffset - 32 - 16, self.frame.size.width, 32);
|
||||
|
||||
CGFloat photosViewSize = TGPhotoThumbnailSizeForCurrentScreen().height + 4 * 2;
|
||||
|
@ -194,6 +194,8 @@
|
||||
{
|
||||
if (!hasZoom)
|
||||
[_zoomView hideAnimated:true];
|
||||
|
||||
[_zoomModeView setHidden:!hasZoom animated:true];
|
||||
}
|
||||
|
||||
#pragma mark - Video
|
||||
@ -233,11 +235,6 @@
|
||||
completion(true);
|
||||
}
|
||||
|
||||
- (void)layoutPreviewRelativeViews
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
- (void)setDocumentFrameHidden:(bool)hidden
|
||||
|
@ -282,20 +282,20 @@
|
||||
|
||||
switch (gestureRecognizer.state) {
|
||||
case UIGestureRecognizerStateBegan:
|
||||
self.zoomChanged(_zoomLevel, false);
|
||||
self.zoomChanged(_zoomLevel, false, false);
|
||||
break;
|
||||
|
||||
case UIGestureRecognizerStateChanged:
|
||||
_zoomLevel = MAX(0.5, MIN(10.0, _zoomLevel - translation.x / 100.0));
|
||||
self.zoomChanged(_zoomLevel, false);
|
||||
self.zoomChanged(_zoomLevel, false, false);
|
||||
break;
|
||||
|
||||
case UIGestureRecognizerStateEnded:
|
||||
self.zoomChanged(_zoomLevel, true);
|
||||
self.zoomChanged(_zoomLevel, true, false);
|
||||
break;
|
||||
|
||||
case UIGestureRecognizerStateCancelled:
|
||||
self.zoomChanged(_zoomLevel, true);
|
||||
self.zoomChanged(_zoomLevel, true, false);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -307,17 +307,17 @@
|
||||
|
||||
- (void)leftPressed {
|
||||
[self setZoomLevel:0.5 animated:true];
|
||||
self.zoomChanged(0.5, true);
|
||||
self.zoomChanged(0.5, true, true);
|
||||
}
|
||||
|
||||
- (void)centerPressed {
|
||||
[self setZoomLevel:1.0 animated:true];
|
||||
self.zoomChanged(1.0, true);
|
||||
self.zoomChanged(1.0, true, true);
|
||||
}
|
||||
|
||||
- (void)rightPressed {
|
||||
[self setZoomLevel:2.0 animated:true];
|
||||
self.zoomChanged(2.0, true);
|
||||
self.zoomChanged(2.0, true, true);
|
||||
}
|
||||
|
||||
- (void)setZoomLevel:(CGFloat)zoomLevel {
|
||||
@ -329,33 +329,39 @@
|
||||
_zoomLevel = zoomLevel;
|
||||
if (zoomLevel < 1.0) {
|
||||
NSString *value = [NSString stringWithFormat:@"%.1fx", zoomLevel];
|
||||
if ([value isEqual:@"1.0x"]) {
|
||||
value = @"0.9x";
|
||||
if ([value isEqual:@"1,0x"]) {
|
||||
value = @"0,9x";
|
||||
}
|
||||
value = [value stringByReplacingOccurrencesOfString:@"." withString:@","];
|
||||
[_leftItem setValue:value selected:true animated:animated];
|
||||
[_centerItem setValue:@"1" selected:false animated:animated];
|
||||
[_rightItem setValue:@"2" selected:false animated:animated];
|
||||
} else if (zoomLevel < 2.0) {
|
||||
[_leftItem setValue:@"0.5" selected:false animated:animated];
|
||||
[_leftItem setValue:@"0,5" selected:false animated:animated];
|
||||
if ((zoomLevel - 1.0) < 0.1) {
|
||||
[_centerItem setValue:@"1x" selected:true animated:animated];
|
||||
} else {
|
||||
NSString *value = [NSString stringWithFormat:@"%.1fx", zoomLevel];
|
||||
if ([value isEqual:@"1.0x"]) {
|
||||
value = [value stringByReplacingOccurrencesOfString:@"." withString:@","];
|
||||
if ([value isEqual:@"1,0x"]) {
|
||||
value = @"1x";
|
||||
} else if ([value isEqual:@"2,0x"]) {
|
||||
value = @"1,9x";
|
||||
}
|
||||
[_centerItem setValue:value selected:true animated:animated];
|
||||
}
|
||||
[_rightItem setValue:@"2" selected:false animated:animated];
|
||||
} else {
|
||||
[_leftItem setValue:@"0.5" selected:false animated:animated];
|
||||
[_leftItem setValue:@"0,5" selected:false animated:animated];
|
||||
[_centerItem setValue:@"1" selected:false animated:animated];
|
||||
|
||||
CGFloat near = round(zoomLevel);
|
||||
if (ABS(zoomLevel - near) < 0.1) {
|
||||
[_rightItem setValue:[NSString stringWithFormat:@"%dx", (int)zoomLevel] selected:true animated:animated];
|
||||
} else {
|
||||
[_rightItem setValue:[NSString stringWithFormat:@"%.1fx", zoomLevel] selected:true animated:animated];
|
||||
NSString *value = [NSString stringWithFormat:@"%.1fx", zoomLevel];
|
||||
value = [value stringByReplacingOccurrencesOfString:@"." withString:@","];
|
||||
[_rightItem setValue:value selected:true animated:animated];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -406,6 +412,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||
{
|
||||
_interfaceOrientation = interfaceOrientation;
|
||||
_leftItem.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(interfaceOrientation));
|
||||
_centerItem.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(interfaceOrientation));
|
||||
_rightItem.transform = CGAffineTransformMakeRotation(TGRotationForInterfaceOrientation(interfaceOrientation));
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
@ -1706,6 +1706,9 @@ UIImage *TGBlurredAlphaImage(UIImage *source, CGSize size)
|
||||
UIImage *TGBlurredRectangularImage(UIImage *source, bool more, CGSize size, CGSize renderSize, uint32_t *averageColor, void (^pixelProcessingBlock)(void *, int, int, int))
|
||||
{
|
||||
CGSize fittedSize = fitSize(size, CGSizeMake(90, 90));
|
||||
if ((int)(fittedSize.width) % 2 != 0) {
|
||||
fittedSize.width += 1.0;
|
||||
}
|
||||
CGSize fittedRenderSize = CGSizeMake(fittedSize.width / size.width * renderSize.width, fittedSize.height / size.height * renderSize.height);
|
||||
|
||||
const struct { int width, height; } blurredContextSize = { (int)fittedSize.width, (int)fittedSize.height };
|
||||
@ -2288,12 +2291,12 @@ UIImage *TGCropBackdropImage(UIImage *source, CGSize size)
|
||||
|
||||
UIImage *TGCameraPositionSwitchImage(UIImage *source, CGSize size)
|
||||
{
|
||||
return TGBlurredRectangularImage(source, false, size, size, NULL, nil);
|
||||
return TGBlurredRectangularImage(source, true, size, size, NULL, nil);
|
||||
}
|
||||
|
||||
UIImage *TGCameraModeSwitchImage(UIImage *source, CGSize size)
|
||||
{
|
||||
return TGBlurredRectangularImage(source, false, size, size, NULL, nil);
|
||||
return TGBlurredRectangularImage(source, true, size, size, NULL, nil);
|
||||
}
|
||||
|
||||
UIImage *TGScaleAndCropImageToPixelSize(UIImage *source, CGSize size, CGSize renderSize, uint32_t *averageColor, void (^pixelProcessingBlock)(void *, int, int, int))
|
||||
|
Loading…
x
Reference in New Issue
Block a user