         focusIndicatorView.alpha = 0.0
         previewView.addSubview(focusIndicatorView)
 
-        flashButton = UIButton(frame: CGRect(x: buttonMargin, y: buttonMargin, width: 70, height: 38))
+        flashButton = UIButton(frame: CGRect(x: viewFrame.origin.x + buttonMargin, y: viewFrame.origin.y + buttonMargin, width: 70, height: 38))
         flashButton.setImage(UIImage(named: "LightningIcon"), for: UIControlState())
         flashButton.setTitle(NSLocalizedString("Off", comment: "flash off"), for: UIControlState())
         flashButton.addTarget(self, action: #selector(flashButtonTapped(_:)), for: .touchUpInside)

        let tapper = UITapGestureRecognizer(target: self, action: #selector(focusTapGestureRecognized(_:)))
        previewView.addGestureRecognizer(tapper)

        var collectionViewHeight: CGFloat = min(view.frame.size.height / 6, 120)
        let collectionViewBottomMargin: CGFloat = 70
        let cameraButtonHeight: CGFloat = 66

        var containerFrame = CGRect(x: 0, y: view.frame.height - collectionViewBottomMargin - collectionViewHeight, width: view.frame.width, height: collectionViewBottomMargin + collectionViewHeight)
        if captureManager.viewfinderMode == .window {
            let containerHeight = view.frame.height - viewFinderHeight
            containerFrame.origin.y = view.frame.height - containerHeight
            containerFrame.size.height = containerHeight
            collectionViewHeight = containerHeight - cameraButtonHeight
        }

    fileprivate let buttonMargin: CGFloat = 12
    fileprivate var orientation: UIDeviceOrientation = .portrait

    private var viewFrame: CGRect!
    private var viewBounds: CGRect!
    private var subviewsCreated = false


    deinit {
        captureManager.stop(nil)
    }
