自定义相机视图不工作在iOS 8 / Xcode 6 [英] Custom Camera View Not Working on iOS 8/Xcode 6

查看:160
本文介绍了自定义相机视图不工作在iOS 8 / Xcode 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个代码在我的另一个应用程序拍摄照片在自定义相机视图,当我有我的手机上的iOS 7和Xcode 5.1,现在在iOS 8和Xcode 6,相机工作,但我不能在我的leftVertical UIView中看到相机的实时视图。这里是我的代码,将感谢任何帮助谢谢!

So I had this code working on another app of mine to take photos on a custom camera view when I had iOS 7 on my phone and Xcode 5.1, now on iOS 8 and Xcode 6, the camera works but I can't see the live view of the camera in my leftVertical UIView. Here's my code, would appreciate any help Thanks!

#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:在主线程上启动相机捕获,像这样..

In –viewWillAppear: start camera capture on main thread, like this..

dispatch_async(dispatch_get_main_queue(),^ {

dispatch_async(dispatch_get_main_queue(), ^{

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

});

这篇关于自定义相机视图不工作在iOS 8 / Xcode 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆