前言:我是赵大财,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
来源:oschina
链接:https://my.oschina.net/u/1186234/blog/653111