How to record a video of your screen using ReplayKit whilst hiding the HUD element.

Oscar de la Hera
AR Tips And Tricks
Published in
2 min readJul 12, 2018

For a solution to record video without ReplayKit : HERE.

Download an AR camera starter project here.

I needed an image.

PART A: Add your Hidden HUD to your view

Step 1: Create a Hidden Status Bar View Controller.

Create a “HiddenStatusBarViewController.Swift” file and add the following code.

import UIKitclass HiddenStatusBarViewController: UIViewController {override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view.}override func didReceiveMemoryWarning() {super.didReceiveMemoryWarning()// Dispose of any resources that can be recreated.}func prefersStatusBarHidden() -> Bool {return true}/*// MARK: - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigationoverride func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {// Get the new view controller using segue.destinationViewController.// Pass the selected object to the new view controller.}*/}

Step 2: Add a UI Window property to your ViewController

var windowToHideHUD:UIWindow!

Step 3: Instantiate the Window and add the HUD elements to it

Add this to your viewDidLoad()

self.windowToHideHUD = UIWindow(frame: self.view.frame);self.windowToHideHUD.rootViewController = HiddenStatusBarViewController();////////////////////////////// ADD YOUR ELEMENTS HERE //////////////////////////////// THIS IS HOW YOU ADD A SUBVIEW TO THE WINDOW
self.windowToHideHUD.rootViewController?.view.addSubview("YOUR VIEW / THING");
self.windowToHideHUD.makeKeyAndVisible()

PART B: Add the ReplayKit functionality.

Step 1: Add the ReplayKit functionality to your viewcontroller

// Mark: ReplayKitfunc startRecording(){guard RPScreenRecorder.shared().isAvailable else {print("Recording is not available at this time.")return}RPScreenRecorder.shared().isMicrophoneEnabled = true;RPScreenRecorder.shared().startRecording { [unowned self] (error) inguard error == nil else {print("There was an error starting the recording.")return}}}func stopRecording(){print("STOP RECORDING")self.windowToHideHUD.isHidden = true;RPScreenRecorder.shared().stopRecording { [unowned self] (preview, error) inprint("Stopped recording");guard error == nil else {print("There was an error stopping the recording.")return}guard preview != nil else {print("Preview controller is not available.")return}if let unwrappedPreview = preview {unwrappedPreview.previewControllerDelegate = self;self.present(unwrappedPreview, animated: true)}}}func previewControllerDidFinish(_ previewController: RPPreviewViewController) {dismiss(animated: true)self.windowToHideHUD.isHidden = false;}

Step 2 : Wire it up to a button

You can now start a video using:

self.startRecording();

And end the recording using:

self.endRecording();

Oscar

--

--

Oscar de la Hera
AR Tips And Tricks

Oscar is an award-winning Spanish Inventor whose work impacts lives through brands that include Nike, MoMA and Samsung.