videoView Controller 中的摄像机视图适用于 iPhone 但不适用于 iPad
Video camera view in videoViewController works on iPhone but not iPad
我在通用 iOS 应用程序中有一个错误,它不在 iPad 框架中显示相机视图。视图向左偏移。该视图完美地位于 iPhone 中,但不在 iPad 中。原始代码是 2 年前编写的,我想知道 iOS 中是否有更改,现在这部分代码中缺少该更改。
这是我目前拥有的;
self.preview = [AVCaptureVideoPreviewLayer layerWithSession:self.session];
AVCaptureConnection *avcc = [self.preview connection];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
[avcc setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
else
[avcc setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
CGRect rect = [[[self view] layer] bounds];
[self.preview setBounds:CGRectMake(0, 0, rect.size.height, rect.size.width)];
[self.preview setPosition:CGPointMake(CGRectGetMidY(rect), CGRectGetMidX(rect))];
self.preview.videoGravity = AVLayerVideoGravityResizeAspectFill;
根据问题,如果您的项目支持自动布局,我可以建议在 viewDidLayoutSubviews()
中添加这一行。
代码:-
{
CGRect bounds=self.view.layer.bounds;
self.preview.videoGravity = AVLayerVideoGravityResizeAspectFill;
self.preview.bounds=bounds;
self.preview.position=CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
}
我在通用 iOS 应用程序中有一个错误,它不在 iPad 框架中显示相机视图。视图向左偏移。该视图完美地位于 iPhone 中,但不在 iPad 中。原始代码是 2 年前编写的,我想知道 iOS 中是否有更改,现在这部分代码中缺少该更改。
这是我目前拥有的;
self.preview = [AVCaptureVideoPreviewLayer layerWithSession:self.session];
AVCaptureConnection *avcc = [self.preview connection];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
[avcc setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
else
[avcc setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
CGRect rect = [[[self view] layer] bounds];
[self.preview setBounds:CGRectMake(0, 0, rect.size.height, rect.size.width)];
[self.preview setPosition:CGPointMake(CGRectGetMidY(rect), CGRectGetMidX(rect))];
self.preview.videoGravity = AVLayerVideoGravityResizeAspectFill;
根据问题,如果您的项目支持自动布局,我可以建议在 viewDidLayoutSubviews()
中添加这一行。
代码:-
{
CGRect bounds=self.view.layer.bounds;
self.preview.videoGravity = AVLayerVideoGravityResizeAspectFill;
self.preview.bounds=bounds;
self.preview.position=CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
}