我遵循了一个教程,通过一种方式来制作一个自定义但简单的相机应用程序,几乎完全符合我想要的使用需求.我实际上有两个问题需要改变,但我现在将重点关注第一个问题.
以下代码允许使用后置摄像头,但我基本上需要对其进行更改,以便我可以使用前置摄像头.我还会在这里链接我从中获取的视频给予他们的信任,然后我按照其中一位评论者所说的使用前置摄像头但答案根本没有帮助.
https://www.youtube.com/watch?v=Xv1FfqVy-KM
我根本不擅长编码,但试图学习.任何帮助,将不胜感激!非常感谢.
@interface ViewController ()
@end
@implementation ViewController
AVCaptureSession *session;
AVCaptureStillImageOutput *StillImageOutput;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewWillAppear:(BOOL)animated {
session = [[AVCaptureSession alloc] init];
[session setSessionPreset:AVCaptureSessionPresetPhoto];
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 …Run Code Online (Sandbox Code Playgroud)