@@ -203,14 +203,6 @@ open class BarcodeScannerController: UIViewController {
203203 object: nil )
204204 }
205205
206- open override func viewWillAppear( _ animated: Bool ) {
207- super. viewWillAppear ( animated)
208-
209- setupFrames ( )
210- infoView. setupFrames ( )
211- headerView. isHidden = !isBeingPresented
212- }
213-
214206 open override func viewDidAppear( _ animated: Bool ) {
215207 super. viewDidAppear ( animated)
216208 animateFocusView ( )
@@ -268,7 +260,7 @@ open class BarcodeScannerController: UIViewController {
268260 output. metadataObjectTypes = metadata
269261 videoPreviewLayer? . session = captureSession
270262
271- setupFrames ( )
263+ view . setNeedsLayout ( )
272264 }
273265
274266 // MARK: - Reset
@@ -310,25 +302,30 @@ open class BarcodeScannerController: UIViewController {
310302 }
311303
312304 // MARK: - Layout
305+ open override func viewWillLayoutSubviews( ) {
306+ super. viewWillLayoutSubviews ( )
313307
314- /**
315- Sets frames of the subviews.
316- */
317- func setupFrames( ) {
318308 headerView. frame = CGRect ( x: 0 , y: 0 , width: view. frame. width, height: 64 )
319309 flashButton. frame = CGRect ( x: view. frame. width - 50 , y: 73 , width: 37 , height: 37 )
320310 infoView. frame = infoFrame
321311
322312 if let videoPreviewLayer = videoPreviewLayer {
323313 videoPreviewLayer. frame = view. layer. bounds
324-
325- if videoPreviewLayer. connection != nil {
326- videoPreviewLayer. connection. videoOrientation = . portrait
314+ if let connection = videoPreviewLayer. connection, connection. isVideoOrientationSupported {
315+ switch ( UIApplication . shared. statusBarOrientation) {
316+ case . portrait: connection. videoOrientation = . portrait
317+ case . landscapeRight: connection. videoOrientation = . landscapeRight
318+ case . landscapeLeft: connection. videoOrientation = . landscapeLeft
319+ case . portraitUpsideDown: connection. videoOrientation = . portraitUpsideDown
320+ default : connection. videoOrientation = . portrait
321+ }
327322 }
328323 }
329324
330325 center ( subview: focusView, inSize: CGSize ( width: 218 , height: 150 ) )
331326 center ( subview: settingsButton, inSize: CGSize ( width: 150 , height: 50 ) )
327+
328+ headerView. isHidden = !isBeingPresented
332329 }
333330
334331 /**
@@ -345,12 +342,6 @@ open class BarcodeScannerController: UIViewController {
345342 height: size. height)
346343 }
347344
348- // MARK: - Orientation
349-
350- open override var supportedInterfaceOrientations : UIInterfaceOrientationMask {
351- return . portrait
352- }
353-
354345 // MARK: - Animations
355346
356347 /**
@@ -386,13 +377,13 @@ open class BarcodeScannerController: UIViewController {
386377 focusView. layer. removeAllAnimations ( )
387378 focusView. isHidden = false
388379
389- setupFrames ( )
390-
391380 UIView . animate ( withDuration: 1.0 , delay: 0 ,
392381 options: [ . repeat , . autoreverse, . beginFromCurrentState] ,
393382 animations: {
394383 self . center ( subview: self . focusView, inSize: CGSize ( width: 280 , height: 80 ) )
395384 } , completion: nil )
385+
386+ view. setNeedsLayout ( )
396387 }
397388
398389 // MARK: - Actions
0 commit comments