Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

how to screen record swift stackoverflow

import ReplayKit

@IBAction func toggleRecording(_ sender: UIBarButtonItem) {
    let r = RPScreenRecorder.shared()

    guard r.isAvailable else {
        print("ReplayKit unavailable")
        return
    }
    
    if r.isRecording {
        self.stopRecording(sender, r)
        
    }
    else {
        self.startRecording(sender, r)
    }
}

func startRecording(_ sender: UIBarButtonItem, _ r: RPScreenRecorder) {
    
    r.startRecording(handler: { (error: Error?) -> Void in
        if error == nil { // Recording has started
            sender.title = "Stop"
        } else {
            // Handle error
            print(error?.localizedDescription ?? "Unknown error")
        }
    })
}

func stopRecording(_ sender: UIBarButtonItem, _ r: RPScreenRecorder) {
    r.stopRecording( handler: { previewViewController, error in

        sender.title = "Record"
        
        if let pvc = previewViewController {

            if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.pad {
                pvc.modalPresentationStyle = UIModalPresentationStyle.popover
                pvc.popoverPresentationController?.sourceRect = CGRect.zero
                pvc.popoverPresentationController?.sourceView = self.view
            }

            pvc.previewControllerDelegate = self
            self.present(pvc, animated: true, completion: nil)
        }
        else if let error = error {
            print(error.localizedDescription)
        }
        
    })
}

// MARK: RPPreviewViewControllerDelegate
func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
    previewController.dismiss(animated: true, completion: nil)
}
Comment

PREVIOUS NEXT
Code Example
Swift :: Swift Join Two Strings 
Swift :: waiting for all the threads to finish swift 
Swift :: how to multiply numbers in array swift 
Swift :: swift loop through array of objet 
Swift :: Swift is case-sensitive. So A and a are different variables 
Swift :: int in swift 
Swift :: uiviewcontroller title color 
Swift :: swift array chunks 
Swift :: Swift Code Reusability 
Swift :: swift ranges 
Swift :: fullscreencover swiftui 
Swift :: single word search swift 
Swift :: uilabel without constraint 
Swift :: Blinking effect on UILabel 
Swift :: Swift for Loop With Range 
Swift :: Swift Labeled Statement with continue 
Swift :: swift loop site:stackoverflow.com 
Swift :: Swift Function with Return Multiple Values 
Swift :: swift enumeration 
Swift :: flutter create custom appbar 
Ruby :: how to delete a table in rails 
Ruby :: ruby temporary files 
Ruby :: rails migration polymorphic references 
Ruby :: rails difference in minutes between 2 datetime 
Ruby :: rails g model 
Ruby :: sort hash ruby 
Ruby :: generate csv ruby 
Ruby :: times ruby 
Ruby :: ruby rails controller 
Ruby :: write csv with header ruby 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =