Sie sollten Ihre Ausrichtung AVCaptureSession
jedes Mal einstellen, wenn die Ausrichtung des Geräts geändert wird.
Fügen Sie einen Notification Observer hinzu, um Änderungen der Geräteausrichtung zu beobachten, und stellen Sie dann die Ausrichtung AVCaptureSession
entsprechend der Geräteausrichtung ein.
Obj-C:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged)
name:UIDeviceOrientationDidChangeNotification
object:nil];
-(void) orientationChanged
{
if (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
[_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPortraitUpsideDown];
if (self.interfaceOrientation == UIInterfaceOrientationPortrait)
[_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPortrait];
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
[_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationLandscapeLeft];
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
[_previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
}
Swift 2:
hinzufügen irgendwo Beobachter, zum Beispiel in viewDidLoad
Verfahren.
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(orientationChanged), name: UIDeviceOrientationDidChangeNotification, object: nil)
Dann:
func orientationChanged(){
let deviceOrientation = UIDevice.currentDevice().orientation
if deviceOrientation == UIDeviceOrientation.PortraitUpsideDown {
previewLayer.connection.videoOrientation = AVCaptureVideoOrientation.PortraitUpsideDown
}
else if deviceOrientation == UIDeviceOrientation.Portrait {
previewLayer.connection.videoOrientation = AVCaptureVideoOrientation.Portrait
}
else if deviceOrientation == UIDeviceOrientation.LandscapeLeft {
previewLayer.connection.videoOrientation = AVCaptureVideoOrientation.LandscapeLeft
}
else if deviceOrientation == UIDeviceOrientation.LandscapeRight {
previewLayer.connection.videoOrientation = AVCaptureVideoOrientation.LandscapeRight
}
}
Sie können auch alle Ihre Code zur Verfügung stellen oder auf diese Frage suchen, die gefragt wurde, bevor es kann helfen. AVCaptureSession with multiple orientations issue
Vielleicht könnten Sie Ihren Kommentar so bearbeiten, dass es in swift nützlich ist? – mafioso
Ok, ich werde mit Swift-Code aktualisieren. –