码迷,mamicode.com
首页 > 移动开发 > 详细

iOS的录屏功能

时间:2018-12-17 02:04:51      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:size   国内   support   preview   ppc   很多   了解   dev   bounds   

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的录屏功能

标签:size   国内   support   preview   ppc   很多   了解   dev   bounds   

原文地址:https://www.cnblogs.com/txfd/p/10128807.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!