Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 无法更改AVCaptureConnection方向_Iphone_Ios - Fatal编程技术网

Iphone 无法更改AVCaptureConnection方向

Iphone 无法更改AVCaptureConnection方向,iphone,ios,Iphone,Ios,我想更改前摄像头的视频方向, 所以我选择了previewLayer.orientation,它确实有效。 由于该方法在IOS6中已被弃用,因此我收到了一条使用previewLayer.connection.videoOrientation的警告 但是我无法从previewLayer访问连接属性 - (void)addDeviceInput { [session beginConfiguration]; [session removeInput:videoInput]; [

我想更改前摄像头的视频方向, 所以我选择了previewLayer.orientation,它确实有效。 由于该方法在IOS6中已被弃用,因此我收到了一条使用previewLayer.connection.videoOrientation的警告 但是我无法从previewLayer访问连接属性

- (void)addDeviceInput {
    [session beginConfiguration];
    [session removeInput:videoInput];
    [self setVideoInput:nil];
    AVCaptureDeviceInput *newDeviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self frontFacingCamera] error:nil];
    if ([session canAddInput:newDeviceInput]) {
        [session addInput:newDeviceInput];
        [self setVideoInput:newDeviceInput];
    }
    newDeviceInput = nil;
    if (previewLayer) {
        [previewLayer removeFromSuperlayer];
        [previewLayer release];
        previewLayer = nil;
    }
    [session commitConfiguration];

}

- (id)setupCameraSession {
    if (!(self = [super init])) {
        return nil;
     }
    self.frameRate = 0;
    session = [[AVCaptureSession alloc] init];
    [session beginConfiguration];
    [session setSessionPreset:AVCaptureSessionPreset352x288];

    [self addDeviceInput]; //invoke previous method 
    AVCaptureVideoDataOutput * newVideoDataOutput = [[AVCaptureVideoDataOutput alloc] init];
    newVideoDataOutput.videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                                    [NSNumber numberWithInt:kCVPixelFormatType_32BGRA],
                                    kCVPixelBufferPixelFormatTypeKey,nil];
    newVideoDataOutput.alwaysDiscardsLateVideoFrames = YES;
    if ([session canAddOutput:newVideoDataOutput]) {
        [session addOutput:newVideoDataOutput];
        [self setVideoOutput:newVideoDataOutput];
    }
    [newVideoDataOutput release];
    self.frameRate = VIDEO_FRAME_RATE;
    [session commitConfiguration];

    AVCaptureVideoPreviewLayer * newPreviewLayer =
    [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
    //[newPreviewLayer setSession:session]; //it doesn't work? and get error 

    [self setPreviewLayer:newPreviewLayer];
    [newPreviewLayer release];

    [session startRunning];
    return self;
}
我得到了错误

错误:执行被中断,原因:试图取消引用无效的ObjC对象或向其发送无法识别的选择器