1
因此,当我在手机上安装iOS 7并在iOS 8上安装Xcode 5.1时,我有另一个应用程序可以在自定义摄像头视图上拍摄照片, Xcode 6,相机工作正常,但我无法在左侧垂直UIView中看到相机的实时视图。这是我的代码,将不胜感激任何帮助谢谢!自定义摄像头视图无法在iOS 8/Xcode 6上工作
#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];
使用在你的if/else语句括号。忽略它们可能会有[非常糟糕的后果](https://www.imperialviolet.org/2014/02/22/applebug.html)。 – mattt 2014-10-02 02:03:58
@mattt我添加了它们,但没有任何改变,但仍然没有相机的实时视图 – adambargh 2014-10-03 02:40:17
这是一个普遍的说法,并不是专门针对这个问题的具体调试。 – mattt 2014-10-03 17:20:44