これは面白い。
アプリへ組み込んで撮影したい画面を表示するコードを追加すると自動的にスクリーンショットが撮れるツール。
デモビデオ。
組み込み自体は簡単で、プロジェクトへいくつかのファイルを追加し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が表示される。

しばらくすると回転してアプリが終了。スクリーンショットはアプリのDocumentsフォルダにできる。

ポートレイトとランドスケープのそれぞれスクリーンショット2枚が自動的に作成された。

肝となる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ページ
多言語対応している場合など、多くのスクリーンショットを取らなければならない場合は重宝しそう。