Skip to content
This repository was archived by the owner on Jun 19, 2025. It is now read-only.

Commit ec31817

Browse files
authored
Merge pull request #155 from wordpress-mobile/issue/135-capture-orientation
Issue/135: Don't silently pass through face up/down device orientations
2 parents 9fdc63e + cb1974c commit ec31817

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Pod/Classes/WPMediaCapturePreviewCollectionView.m

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ - (void)startCapture
100100
self.captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];
101101
self.captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
102102
self.captureVideoPreviewLayer.frame = viewLayer.bounds;
103-
self.captureVideoPreviewLayer.connection.videoOrientation = (AVCaptureVideoOrientation)[[UIDevice currentDevice] orientation];
103+
self.captureVideoPreviewLayer.connection.videoOrientation = [self videoOrientationForInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
104104
[viewLayer addSublayer:_captureVideoPreviewLayer];
105105
});
106106
}
@@ -110,7 +110,22 @@ - (void)startCapture
110110
- (void)deviceOrientationDidChange:(NSNotification *)notification
111111
{
112112
if (self.captureVideoPreviewLayer.connection.supportsVideoOrientation) {
113-
self.captureVideoPreviewLayer.connection.videoOrientation = (AVCaptureVideoOrientation)[[UIDevice currentDevice] orientation];
113+
self.captureVideoPreviewLayer.connection.videoOrientation = [self videoOrientationForInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation]];
114+
}
115+
}
116+
117+
- (AVCaptureVideoOrientation)videoOrientationForInterfaceOrientation:(UIInterfaceOrientation)orientation
118+
{
119+
switch (orientation) {
120+
case UIInterfaceOrientationPortrait:
121+
return AVCaptureVideoOrientationPortrait;
122+
case UIInterfaceOrientationPortraitUpsideDown:
123+
return AVCaptureVideoOrientationPortraitUpsideDown;
124+
case UIInterfaceOrientationLandscapeLeft:
125+
return AVCaptureVideoOrientationLandscapeLeft;
126+
case UIInterfaceOrientationLandscapeRight:
127+
return AVCaptureVideoOrientationLandscapeRight;
128+
default:return AVCaptureVideoOrientationPortrait;
114129
}
115130
}
116131

0 commit comments

Comments
 (0)