[10秒学会]

对着背影说爱祢 提交于 2021-01-10 17:01:37

前言:我是赵大财,10秒学会系列,绝不废话连篇! 力求10秒,让你了解 会用此知识点

//
//  ViewController.m
//  DCReplayKit
//
//  Created by point on 16/4/5.
//  Copyright © 2016年 tshiny. All rights reserved.
//

#import "ViewController.h"
#import <ReplayKit/ReplayKit.h>

@interface ViewController ()<RPPreviewViewControllerDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    RPScreenRecorder *recorder = [RPScreenRecorder sharedRecorder];
    if([recorder isAvailable]) {
        NSLog(@"支持录制");
    }else{
        NSLog(@"不支持录制");
    }
    
    UIButton *startBtn = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 100, 100)];
    [self.view addSubview:startBtn];
    startBtn.backgroundColor = [UIColor blueColor];
    [startBtn setTitle:@"开始录制" forState:UIControlStateNormal];
    [startBtn addTarget:self action:@selector(start:) forControlEvents:UIControlEventTouchUpInside];
    
    
    UIButton *endBtn = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    [self.view addSubview:endBtn];
    endBtn.backgroundColor = [UIColor blueColor];
    [endBtn setTitle:@"结束录制" forState:UIControlStateNormal];
    [endBtn addTarget:self action:@selector(end:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)start:(UIButton *)btn {
    RPScreenRecorder *recorder = [RPScreenRecorder sharedRecorder];
    [recorder startRecordingWithMicrophoneEnabled:YES handler:^(NSError * _Nullable error) {
        if (error) {
            NSLog(@"start recorder error - %@",error);
        }
        [btn setTitle:@"开始啦" forState:UIControlStateNormal];
    }];
    
}

- (void)end:(UIButton *)btn {
    RPScreenRecorder *recorder = [RPScreenRecorder sharedRecorder];
    [recorder stopRecordingWithHandler:^(RPPreviewViewController * _Nullable previewViewController, NSError * _Nullable error) {
        
        previewViewController.previewControllerDelegate = self;
        [self presentViewController:previewViewController animated:NO completion:^{
            NSLog(@"开始播放啦");
        }];
    }];
}

- (void)previewControllerDidFinish:(RPPreviewViewController *)previewController
{
    [previewController dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!