gpt4 book ai didi

ios - 自定义相机 View 不适用于 iOS 8/Xcode 6

转载 作者:行者123 更新时间:2023-12-01 16:38:58 25 4
gpt4 key购买 nike

因此,当我在手机上安装 iOS 7 和 Xcode 5.1(现在在 iOS 8 和 Xcode 6 上)时,我在我的另一个应用程序上使用此代码在自定义相机 View 上拍照,现在在 iOS 8 和 Xcode 6 上,相机工作但我看不到现场在我的 leftVertical UIView 中查看相机。这是我的代码,将不胜感激任何帮助谢谢!

#import <AVFoundation/AVFoundation.h>

session = [[AVCaptureSession alloc] init];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
[session setSessionPreset:AVCaptureSessionPreset352x288];
else
[session setSessionPreset:AVCaptureSessionPreset352x288];

AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error;
AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:&error];
if ([session canAddInput:deviceInput]) {
[session addInput:deviceInput];
}

AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

CALayer *rootLayer = [[self view] layer];
[rootLayer setMasksToBounds:YES];
CGRect frame = self.leftVertical.frame;

[previewLayer setFrame:frame];

[rootLayer insertSublayer:previewLayer atIndex:0];

//////////////////////////

stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG, AVVideoCodecKey, nil];
[stillImageOutput setOutputSettings:outputSettings];

[session addOutput:stillImageOutput];

[session startRunning];

最佳答案

试试这个...

在--viewWillAppear: 在主线程开始摄像头捕捉,像这样..

dispatch_async(dispatch_get_main_queue(), ^{

if (![session isRunning])
{
[session startRunning];
}
});

关于ios - 自定义相机 View 不适用于 iOS 8/Xcode 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25986600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com