2014-10-09 60 views

回答

0

當你安裝攝像頭,你有AVCaptureVideoDataOutput videoDataOutput和AVCaptureVideoPreviewLayer previewLayer。您可以按照以下方式配置它們。

//set the orientation of previewlayer, which is presented to user 
AVCaptureConnection *conncetion = self.previewLayer.connection; 
conncetion.videoOrientation = AVCaptureVideoOrientationLandscapeRight; 

//set the output frame orientation 
AVCaptureConnection *conn = [self.videoDataOutput connectionWithMediaType:AVMediaTypeVideo]; 
conn.videoOrientation = AVCaptureVideoOrientationLandscapeRight; 

在AVCam示例代碼中,當記錄和保存爲文件時。上述兩個被設置爲相同的方向,這是視圖 - 控制的interfaceOrientation:

[[[self movieFileOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]]; 

它觀察設備的方向,這是很好的。