• 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);
                    
                }
            }];
        }
    }
  • 相关阅读:
    PT100高精度测温电路 AD623+REF3030(转)
    STM32|4-20mA输出电路(转)
    串口通讯数据处理算法分析与实现(转)
    stm32_CAN总线知识(转)
    图像的灰度级和动态范围(转)
    图像bayer格式介绍以及bayer插值原理CFA(转)
    用oracle建表,必须注意Oracle 关键字(保留字)
    爬虫的定向爬取与垂直搜索
    开源的网络爬虫以及一些简介和比较
    SQL中的等号、IN、LIKE三者的比较
  • 原文地址:https://www.cnblogs.com/txfd/p/10128807.html
Copyright © 2020-2023  润新知