ReplayKit and iPhone X

Hi,


I am trying to record the screen and microfone inside my application using ReplayKit. It records everything without problems and at the end I present the preview through this code:


recorder.stopRecording { [weak self] (preview, error) in
            guard preview != nil else {
                print("Preview not available")
                return
            }
            preview?.previewControllerDelegate = self
            self?.present(preview!, animated: true, completion: nil)
}


The problem is here, the RPPreviewViewController obtained in the callback does not respect the safe area for iPhone X.

The buttons are too close to the edges and the title is hidden below the notch.

I also tryed to embed the RPPreviewViewController into another UIViewController (a simple wrapper), but it seems like the height is fixed, so if I lower the top part the bottom one goes out of the screen.


Any clue of what I am doing wrong? Any help is appreciated.


Thanks!

Accepted Reply

I could change the position of the bottom bar with this code.


let safeArea = self.view.safeAreaInsets
let safeAreaHeight = self.view.frame.height - (safeArea.top + safeArea.bottom)
let safeAreaWidth = self.view.frame.width - (safeArea.left + safeArea.right)
let scaleX = safeAreaWidth / self.view.frame.width
let scaleY = safeAreaHeight / self.view.frame.height
let scale = min(scaleX, scaleY)
previewViewController.view.transform = CGAffineTransform(scaleX: scale, y: scale)
self.present(previewViewController, animated: true) {
    previewViewController.view.frame.origin.x += safeArea.left
    previewViewController.view.frame.origin.y += safeArea.top
}

Replies

I have the same issue. It seems a bug to me.

You can make the preview view smaller by setting preview.view.transform, but I don't think it's a correct way.

Yes I noticed that the preview is resizable, but the bottom bar (the yellow one with the slider) and the bottom buttons cannot be moved, so they goes out of the screen if I lower the view controller.

I could change the position of the bottom bar with this code.


let safeArea = self.view.safeAreaInsets
let safeAreaHeight = self.view.frame.height - (safeArea.top + safeArea.bottom)
let safeAreaWidth = self.view.frame.width - (safeArea.left + safeArea.right)
let scaleX = safeAreaWidth / self.view.frame.width
let scaleY = safeAreaHeight / self.view.frame.height
let scale = min(scaleX, scaleY)
previewViewController.view.transform = CGAffineTransform(scaleX: scale, y: scale)
self.present(previewViewController, animated: true) {
    previewViewController.view.frame.origin.x += safeArea.left
    previewViewController.view.frame.origin.y += safeArea.top
}

With this workaround it become usable, thank you!

For people coming to this thread from the Web: The accepted answer does not resolve the issue! The PRPreviewViewController is apparently Full Screen and one should just change the modalPresentationStyle to .overFullScreen to see the result fit on iPhones.