これは面白い。
アプリへ組み込んで撮影したい画面を表示するコードを追加すると自動的にスクリーンショットが撮れるツール。
デモビデオ。
組み込み自体は簡単で、プロジェクトへいくつかのファイルを追加しKSScreenshotManagerのサブクラスを作るだけ。
Adding this to your project付属のpythonスクリプトをカスタマイズすればlanguages, devices, project_path, target_name, and app_nameが設定できる。
1. Include KSScreenshotManager in your project. Adding it as a submodule is probably the easiest way to do this. Be sure to check out the WaxSim submodule as well by running git submodule update --init
2. Add KSScreenshotManager.h, KSScreenshotManager.m, KSScreenshotAction.h, KSScreenshotAction.m to your project
3. Subclass KSScreenshotManager and override setupScreenshotActions
4. Customize make_screenshots.py and use it to generate your screenshots
More specifically, you'll probably need to change these variables: languages, devices, project_path, target_name, and app_name
githubではサンプルのアプリが付いていて、これを実行するとUITableViewが表示される。
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwlPfoBYOuW76HY-tCcagkGglhn54kRNxAn9q-o6YryZpFMFHmbT4HXnfsE5AEROAMRaoCBl9QlTrMgZZCREO8-1AEfyr1xHaioYdS00dI-S_hlXA_T-qO76P-ThEBLrPQHvb4E5McxQ4h/s320/130225-0007.jpg)
しばらくすると回転してアプリが終了。スクリーンショットはアプリのDocumentsフォルダにできる。
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqQoryAstW9jtYT27_fsbZc_tX6FxuqshPeErglS5zaP9aKIIH02z1CuV1Ujf39N2Sa33Jt2CwDBu65wuky-zxIjkrxeCu1Cer1JgOCRi-ZBdgxfhds7bxtlsKEIptINXQ4v0dLoUi4eWB/s320/130225-0002.jpg)
ポートレイトとランドスケープのそれぞれスクリーンショット2枚が自動的に作成された。
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYliICgj_vNr6KKkJSVFEdNvx367vUCrWdppoBIIuaWil-gwJ0X1oHNqf22U5ctfdsq5W98tdNLeuLBBzXCtu0RpUxohZRIVDb6xlFg_c_j-mcWgCQ_QX0qUc7_WmTJ-Vjk2I7fjPiKsKo/s320/130225-0003.jpg)
肝となるKSScreenshotManagerのサブクラスはこんな感じ。
- (void)setupScreenshotActions { //Two contrived screenshot actions //Scroll the table view to a different row and take a screenshot //Create a synchronous action //This means the screenshot will automatically be taken after running the actionBlock (after running the run loop to allow view to lay out) KSScreenshotAction *synchronousAction = [KSScreenshotAction actionWithName:@"tableView1" asynchronous:NO actionBlock:^{ NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0]; [[[self tableViewController] tableView] scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO]; } cleanupBlock:^{ [[[self tableViewController] tableView] setContentOffset:CGPointZero]; }]; [self addScreenshotAction:synchronousAction]; :スクリーンショット対象の画面を表示する為の処理を KSScreenshotAction のインスタンスとして定義して KSScreenshotManagerへ追加していく。サンプルでは UITableViewのインスタンスをアプリからもらい、KSScreenshotActionへ渡す blocks内でスクロール位置を制御している。KSScreenshotActionは非同期のタイミング(例えば数秒後)の定義も可能。サンプルでは画面を回転させた後のランドスケープ画面の撮影に使っている。
記事ではその他スクリーンショット画面を作る際のテクニックも紹介されている(任意の日付を表示させるなど)。
githubページ
多言語対応している場合など、多くのスクリーンショットを取らなければならない場合は重宝しそう。