From a0f3f67367fd32fda6f8d1798a5315343a39133c Mon Sep 17 00:00:00 2001 From: James Frost Date: Tue, 14 Mar 2017 10:04:39 +0000 Subject: [PATCH 1/2] Fixes #135: Don't silently pass through face up/down device orientations --- Pod/Classes/WPMediaCapturePreviewCollectionView.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Pod/Classes/WPMediaCapturePreviewCollectionView.m b/Pod/Classes/WPMediaCapturePreviewCollectionView.m index 3e50d57f..68be1aca 100644 --- a/Pod/Classes/WPMediaCapturePreviewCollectionView.m +++ b/Pod/Classes/WPMediaCapturePreviewCollectionView.m @@ -100,7 +100,7 @@ - (void)startCapture self.captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session]; self.captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; self.captureVideoPreviewLayer.frame = viewLayer.bounds; - self.captureVideoPreviewLayer.connection.videoOrientation = (AVCaptureVideoOrientation)[[UIDevice currentDevice] orientation]; + self.captureVideoPreviewLayer.connection.videoOrientation = [self videoOrientationForDeviceOrientation:[[UIDevice currentDevice] orientation]]; [viewLayer addSublayer:_captureVideoPreviewLayer]; }); } @@ -110,10 +110,19 @@ - (void)startCapture - (void)deviceOrientationDidChange:(NSNotification *)notification { if (self.captureVideoPreviewLayer.connection.supportsVideoOrientation) { - self.captureVideoPreviewLayer.connection.videoOrientation = (AVCaptureVideoOrientation)[[UIDevice currentDevice] orientation]; + self.captureVideoPreviewLayer.connection.videoOrientation = [self videoOrientationForDeviceOrientation:[[UIDevice currentDevice] orientation]]; } } +- (AVCaptureVideoOrientation)videoOrientationForDeviceOrientation:(UIDeviceOrientation)orientation +{ + if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown) { + return AVCaptureVideoOrientationPortrait; + } + + return (AVCaptureVideoOrientation)orientation; +} + - (BOOL)isAccessibilityElement { return YES; From cb1974c0d03f41dea01cd57a97911fbb9111aceb Mon Sep 17 00:00:00 2001 From: James Frost Date: Tue, 14 Mar 2017 12:25:53 +0000 Subject: [PATCH 2/2] Updated orientation changes to use UIInterfaceOrientation. --- .../WPMediaCapturePreviewCollectionView.m | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Pod/Classes/WPMediaCapturePreviewCollectionView.m b/Pod/Classes/WPMediaCapturePreviewCollectionView.m index 68be1aca..1c234bf6 100644 --- a/Pod/Classes/WPMediaCapturePreviewCollectionView.m +++ b/Pod/Classes/WPMediaCapturePreviewCollectionView.m @@ -100,7 +100,7 @@ - (void)startCapture self.captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session]; self.captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; self.captureVideoPreviewLayer.frame = viewLayer.bounds; - self.captureVideoPreviewLayer.connection.videoOrientation = [self videoOrientationForDeviceOrientation:[[UIDevice currentDevice] orientation]]; + self.captureVideoPreviewLayer.connection.videoOrientation = [self videoOrientationForInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]]; [viewLayer addSublayer:_captureVideoPreviewLayer]; }); } @@ -110,17 +110,23 @@ - (void)startCapture - (void)deviceOrientationDidChange:(NSNotification *)notification { if (self.captureVideoPreviewLayer.connection.supportsVideoOrientation) { - self.captureVideoPreviewLayer.connection.videoOrientation = [self videoOrientationForDeviceOrientation:[[UIDevice currentDevice] orientation]]; + self.captureVideoPreviewLayer.connection.videoOrientation = [self videoOrientationForInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]]; } } -- (AVCaptureVideoOrientation)videoOrientationForDeviceOrientation:(UIDeviceOrientation)orientation +- (AVCaptureVideoOrientation)videoOrientationForInterfaceOrientation:(UIInterfaceOrientation)orientation { - if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown) { - return AVCaptureVideoOrientationPortrait; + switch (orientation) { + case UIInterfaceOrientationPortrait: + return AVCaptureVideoOrientationPortrait; + case UIInterfaceOrientationPortraitUpsideDown: + return AVCaptureVideoOrientationPortraitUpsideDown; + case UIInterfaceOrientationLandscapeLeft: + return AVCaptureVideoOrientationLandscapeLeft; + case UIInterfaceOrientationLandscapeRight: + return AVCaptureVideoOrientationLandscapeRight; + default:return AVCaptureVideoOrientationPortrait; } - - return (AVCaptureVideoOrientation)orientation; } - (BOOL)isAccessibilityElement