1
デバイスを横向きの左から右に、またはその逆に回転させると、AVCaptureVideoPreviewLayerが上下反転します。デバイスをポートレートモードからランドスケープモードに回転させると、完全に正常に動作します。これは私のコード最終的にそれをやっAVCaptureVideoPreviewLayerローテーションが動作しない
{ override func viewWillLayoutSubviews() {
let orientation: UIDeviceOrientation = UIDevice.currentDevice().orientation
if(buttonsview.isDescendantOfView(self.view)){
buttonsview.removeFromSuperview()
}else{
}
switch (orientation)
{
case .Portrait:
previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.Portrait
previewLayer.frame = self.view.bounds
var frame = buttonsview.frame
frame.size.width = 320
frame.size.height = 50
let totalWidth : CGFloat = self.view.bounds.size.width
var x:CGFloat = 0.0;
if(totalWidth>320)
{
x = (totalWidth-320.0)/2.0
}
frame.origin.x = x
frame.origin.y = self.view.bounds.size.height-50
buttonsview.frame = frame
buttonsview.layoutSubviews()
view.addSubview(buttonsview)
self.activityView.center = self.view.center
break
case .LandscapeRight:
previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.LandscapeLeft
previewLayer.frame = self.view.bounds
var frame = buttonsview.frame
frame.size.width = 320
frame.size.height = 50
let totalWidth : CGFloat = self.view.bounds.size.width
var x:CGFloat = 0.0;
if(totalWidth>320)
{
x = (totalWidth-320.0)/2.0
}
frame.origin.x = x
frame.origin.y = self.view.bounds.size.height-50
buttonsview.frame = frame
view.addSubview(buttonsview)
self.activityView.center = self.view.center
break
case .LandscapeLeft:
previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight
previewLayer.frame = self.view.bounds
var frame = buttonsview.frame
frame.size.width = 320
frame.size.height = 50
let totalWidth : CGFloat = self.view.bounds.size.width
var x:CGFloat = 0.0;
if(totalWidth>320)
{
x = (totalWidth-320.0)/2.0
}
frame.origin.x = x
frame.origin.y = self.view.bounds.size.height-50
buttonsview.frame = frame
view.addSubview(buttonsview)
self.activityView.center = self.view.center
break
case .PortraitUpsideDown:
previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.PortraitUpsideDown
previewLayer.frame = self.view.bounds
var frame = buttonsview.frame
frame.size.width = 320
frame.size.height = 50
let totalWidth : CGFloat = self.view.bounds.size.width
var x:CGFloat = 0.0;
if(totalWidth>320)
{
x = (totalWidth-320.0)/2.0
}
frame.origin.x = x
frame.origin.y = self.view.bounds.size.height-50
buttonsview.frame = frame
buttonsview.layoutSubviews()
view.addSubview(buttonsview)
self.activityView.center = self.view.center
break
case .Unknown:
previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.LandscapeLeft
previewLayer.frame = self.view.bounds
var frame = buttonsview.frame
frame.size.width = 320
frame.size.height = 50
let totalWidth : CGFloat = self.view.bounds.size.width
var x:CGFloat = 0.0;
if(totalWidth>320)
{
x = (totalWidth-320.0)/2.0
}
frame.origin.x = x
frame.origin.y = self.view.bounds.size.height-50
buttonsview.frame = frame
buttonsview.layoutSubviews()
view.addSubview(buttonsview)
self.activityView.center = self.view.center
break
default:
previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.Portrait
previewLayer.frame = self.view.bounds
var frame = buttonsview.frame
frame.size.width = 320
frame.size.height = 50
let totalWidth : CGFloat = self.view.bounds.size.width
var x:CGFloat = 0.0;
if(totalWidth>320)
{
x = (totalWidth-320.0)/2.0
}
frame.origin.x = x
frame.origin.y = self.view.bounds.size.height-50
buttonsview.frame = frame
buttonsview.layoutSubviews()
view.addSubview(buttonsview)
self.activityView.center = self.view.center
break
}
}
}