指定したビューを録画して .movファイルを作成するライブラリ。
こんな感じで使う。
Glimpse *glimpse = [[Glimpse alloc] init];
// Start recording and tell Glimpse what to do when you are finished
[glimpse startRecordingView:self.view withCallback:^(NSURL *fileOuputURL) {
NSLog(@"DONE WITH OUTPUT: %@", fileOuputURL.absoluteString);
}];
:
// Since our animation is complete, lets tell Glimpse to stop recording.
[glimpse stop];付属のデモではビュー上で実行したアニメーションの様子を録画していた。ライブラリとしての利用の他、ソースコードも参考になる。
GCDを使った定期処理実行。ビューのスナップショット(フレーム)を撮るのに dispatch_sourceを使っている。
__weak typeof(self) weakSelf = self;
_queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, _queue);
dispatch_source_set_timer(_source, dispatch_time(DISPATCH_TIME_NOW, 0), 0.15 * NSEC_PER_SEC, 0 * NSEC_PER_SEC);
dispatch_source_set_event_handler(_source, ^{
dispatch_sync(dispatch_get_main_queue(), ^{
UIImage *viewImage = [weakSelf imageFromView:weakSelf.sourceView];
[weakSelf.writer writeFrameWithImage:[viewImage copy]];
});
});
dispatch_resume(_source);また GlimpseAssetWriterというクラスが用意されていて、集まったフレームを .movファイルに書きだす処理を行っている。AVAssetWriterの使い方の参考になる。


