设为首页 - 加入收藏 焦点技术网
热搜:java
当前位置:首页 >

[10秒学会] - iOS录制屏幕 ReplayKit

2016-04-05 21:50:11.0 java  
导读:[10秒学会] - iOS录制屏幕 ReplayKit。。。

前言:我是赵大财,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


(编辑: 赵大财)

网友评论
相关文章