我正在使用相机(AVCapture 输入/输出)制作一个功能。现在我遇到了如下问题。
当 iPhone 一次倒置(180 度)时,不会调用“layoutSubviews”。
(如果分两步旋转 90 度和 90 度,则每次旋转都会调用“layoutSubviews”)
我正在使用 AVCaptureVideoPreviewLayer 来显示相机输出。
为了旋转预览层,我编写了如下代码。
- (void)layoutSubviews
{
[super layoutSubviews];
[_previewLayer setFrame:self.bounds];
[self setVideoOrientation];
}
- (void)setVideoOrientation
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
AVCaptureVideoOrientation videoOrientation = AVCaptureVideoOrientationPortrait;
switch (orientation) {
case UIInterfaceOrientationPortrait:
videoOrientation = AVCaptureVideoOrientationPortrait;
break;
case UIInterfaceOrientationPortraitUpsideDown:
videoOrientation = AVCaptureVideoOrientationPortraitUpsideDown;
break;
case UIInterfaceOrientationLandscapeLeft:
videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
break;
case UIInterfaceOrientationLandscapeRight:
videoOrientation = AVCaptureVideoOrientationLandscapeRight;
break;
default:
break;
}
[_previewLayer.connection setVideoOrientation:videoOrientation];
}
如果您知道的话,能否告诉我一个在 180 度旋转中一次调用“layoutSubviews”的好方法。