2015-08-12 5 views

Antwort

14

Erkennen und wenden Sie es an viewWillLayoutSubviews.

Hier ist, wie:

override func viewWillLayoutSubviews() { 

    let orientation: UIDeviceOrientation = UIDevice.currentDevice().orientation 
    print(orientation) 

    switch (orientation) { 
    case .Portrait: 
     previewLayer?.connection.videoOrientation = .Portrait 
    case .LandscapeRight: 
     previewLayer?.connection.videoOrientation = .LandscapeLeft 
    case .LandscapeLeft: 
     previewLayer?.connection.videoOrientation = .LandscapeRight 
    default: 
     previewLayer?.connection.videoOrientation = .Portrait 
    } 
} 
+0

thankyou Sir ... Sie meinen Tag gerettet ... diese Zeile hinzufügen, bevor Pause previewLayer.frame = selbst helfen .view.bounds –

+1

Dies muss für den neuesten Swift aktualisiert werden. Beachten Sie, dass die Videoausrichtung aus der Geräteausrichtung für Querformat-Modi herausgedreht wird. –

0

Update für Swift 3

override func viewWillLayoutSubviews() { 

    let orientation: UIDeviceOrientation = UIDevice.current.orientation 
    print(orientation) 

    switch (orientation) { 
    case .portrait: 
     videoPreviewLayer?.connection.videoOrientation = .portrait 
    case .landscapeRight: 
     videoPreviewLayer?.connection.videoOrientation = .landscapeLeft 
    case .landscapeLeft: 
     videoPreviewLayer?.connection.videoOrientation = .landscapeRight 
    case .portraitUpsideDown: 
      videoPreviewLayer?.connection.videoOrientation = .portraitUpsideDown 
    default: 
     videoPreviewLayer?.connection.videoOrientation = .portraitUpsideDown 
    } 
} 
Verwandte Themen