Fix support orientation changes in Camera Preview

Bug: webrtc:8532
Change-Id: I2a3cc6974af711f1be6a55a6a1e04e7189175bd3
Reviewed-on: https://webrtc-review.googlesource.com/23220
Reviewed-by: Anders Carlsson <andersc@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Commit-Queue: Anders Carlsson <andersc@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20702}
This commit is contained in:
Gustavo Garcia gustavo@lifeonair.com
2017-11-15 16:03:18 +02:00
committed by Commit Bot
parent 6581f21f0e
commit 19d77c1bbb
3 changed files with 48 additions and 0 deletions

View File

@ -63,6 +63,10 @@
[session addDelegate:self]; [session addDelegate:self];
} }
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
#pragma mark - ARDAppClientDelegate #pragma mark - ARDAppClientDelegate
- (void)appClient:(ARDAppClient *)client - (void)appClient:(ARDAppClient *)client

View File

@ -53,6 +53,9 @@
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array> </array>
<key>UIAppFonts</key> <key>UIAppFonts</key>
<array> <array>

View File

@ -23,6 +23,26 @@
return [AVCaptureVideoPreviewLayer class]; return [AVCaptureVideoPreviewLayer class];
} }
- (instancetype)initWithFrame:(CGRect)aRect {
self = [super initWithFrame:aRect];
if (self) {
[self addOrientationObserver];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder*)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self addOrientationObserver];
}
return self;
}
- (void)dealloc {
[self removeOrientationObserver];
}
- (void)setCaptureSession:(AVCaptureSession *)captureSession { - (void)setCaptureSession:(AVCaptureSession *)captureSession {
if (_captureSession == captureSession) { if (_captureSession == captureSession) {
return; return;
@ -34,6 +54,10 @@
[RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession [RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeCaptureSession
block:^{ block:^{
previewLayer.session = captureSession; previewLayer.session = captureSession;
[RTCDispatcher dispatchAsyncOnType:RTCDispatcherTypeMain
block:^{
[self setCorrectVideoOrientation];
}];
}]; }];
}]; }];
} }
@ -45,6 +69,10 @@
[self setCorrectVideoOrientation]; [self setCorrectVideoOrientation];
} }
-(void)orientationChanged:(NSNotification *)notification {
[self setCorrectVideoOrientation];
}
- (void)setCorrectVideoOrientation { - (void)setCorrectVideoOrientation {
// Get current device orientation. // Get current device orientation.
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
@ -71,6 +99,19 @@
#pragma mark - Private #pragma mark - Private
- (void)addOrientationObserver {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)removeOrientationObserver {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (AVCaptureVideoPreviewLayer *)previewLayer { - (AVCaptureVideoPreviewLayer *)previewLayer {
return (AVCaptureVideoPreviewLayer *)self.layer; return (AVCaptureVideoPreviewLayer *)self.layer;
} }