iOS的录屏功能

Posted 田丰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS的录屏功能相关的知识,希望对你有一定的参考价值。

ios的录屏功能其实没什么好说的,因为网上的教程很多,但是网上的Demo无一例外几乎都有一个bug,那就是iPad上会出现闪退,这也体现了国内的教程文档的一个特点,就是抄袭,教程几乎千篇一律,bug也是一摸一样,经过多次测试,终于找着了解决方案。

废话少说,代码献上。

//开始录屏
extern "C" void startRecord() {
    NSLog(@"开始录屏");
    if ([RPScreenRecorder sharedRecorder].isRecording) {
        return;
    }
//        [[RPScreenRecorder sharedRecorder] startRecordingWithHandler:^(NSError * _Nullable error) {
////            UnitySendMessage("Buttons", "RecordCallback", [RPScreenRecorder sharedRecorder].isRecording ? "true" : "false");
//        }];
    if (isSupportReplayKit()) {
        [[RPScreenRecorder sharedRecorder] startRecordingWithMicrophoneEnabled:YES handler:^(NSError * _Nullable error) {
            NSLog(@"steve :%@", error);
            //处理发生的错误,如设用户权限原因无法开始录制等
        }];
    }

}


//结束录屏
extern "C" void stopRecord() {
    UIButton *sender = [UIButton buttonWithType:(UIButtonTypeRoundedRect)];
    NSLog(@"停止录屏");
    if ([RPScreenRecorder sharedRecorder].isRecording) {
        NSLog(@"正在录屏中");
        [[RPScreenRecorder sharedRecorder] stopRecordingWithHandler:^(RPPreviewViewController * _Nullable previewViewController, NSError * _Nullable error) {
            if (previewViewController) {
                if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
                    previewViewController.previewControllerDelegate = previewDelegate;
                    
                    previewViewController.preferredContentSize = CGSizeMake(1536, 2048);
                    previewViewController.modalPresentationStyle = UIModalPresentationPopover;
                    UIPopoverPresentationController *popoverpresentationController = previewViewController.popoverPresentationController;
                    [GetAppController().window.rootViewController presentViewController:previewViewController animated:YES completion:^{
                        UnityPause(YES);
                    }];
                    popoverpresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
                    popoverpresentationController.sourceRect = sender.bounds;
                    popoverpresentationController.sourceView = sender;
                    }else{
                        previewViewController.previewControllerDelegate = previewDelegate;
                        [GetAppController().window.rootViewController presentViewController:previewViewController animated:YES completion:^{
                            UnityPause(YES);
                        }];
                    }
                   UnitySendMessage("Canvas/Root/gamepanel(Clone)", "HideStopRecordButton", @"".UTF8String);
                
            }
        }];
    }
}

 

以上是关于iOS的录屏功能的主要内容,如果未能解决你的问题,请参考以下文章

联想怎么录屏

免费开源的录屏软件Captura使用安装配置

n卡自带的录屏驱动录制出来的视频帧数低很卡怎么解决,录制的时候玩起来都很流畅?

羽云录屏——简述

有没有免费的录屏软件

win10怎么录屏?windows自带录屏功能怎么用