Top Banner
Core Graphics on watchOS 2 修一 @shu223 2015.7.14 potatotips #19
47

Core Graphics on watchOS 2

Aug 07, 2015

Download

Mobile

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Core Graphics on watchOS 2

Core Graphics on

watchOS 2堤 修一 @shu223 2015.7.14 potatotips #19

Page 2: Core Graphics on watchOS 2

• iOS専業フリーランス

• ブログ『Over&Out その後』

• 著書

- 『iOS×BLE Core Bluetoothプログラミング』

- 『iOSアプリ開発 達人のレシピ100』

堤 修一

Page 3: Core Graphics on watchOS 2

お手伝いしたプロダクト(BLE関連)

Music for the Deaf

Page 4: Core Graphics on watchOS 2

お手伝いしたプロダクト(Watch関連)

よしだっち(DLE)

鷹の爪団の吉田君を育成するアプリ

WatchMe(Pocket Supernova) Watch に最適化されたビデオメッセージングアプリ。ウォッチで動画メッセージのプレビュー、素早い返信ができる

※お手伝いしたのは開発の初期、ウォッチ側

メール、Facebookメッセージ、TwitterのDM等を一元管理するアプリ

Swingmail(BHI)

※ウォッチ機能は現在開発中

Page 5: Core Graphics on watchOS 2

iOS 9 / watchOS 2 関連のこれまでのアウトプット

おさらい

Page 6: Core Graphics on watchOS 2

API Diffs から見る iOS 9 の新機能

• 基調講演やニュース記事を見るだけではわからない、iOS 9

の細かい新機能を「API Diffs」「What’s new」から抜粋

• http://d.hatena.ne.jp/shu223/20150609/1433813938

Page 7: Core Graphics on watchOS 2

watchOS-2-Sampler• watchOS 2 の新機能のサンプルコード集

- Accelerometer - Gyroscope - Pedometer - Heart Rate - Table Animations - Animated Properties - Audio Rec & Play - Picker Styles - Taptic Engine - Alert - Animation with Digital Crown - Interactive Messaging - Open System URL - Audio File Player

• GitHub で公開中

- github.com/shu223/watchOS-2-Sampler

• 紹介記事

- d.hatena.ne.jp/shu223/20150614/1434313771

Page 8: Core Graphics on watchOS 2

watchOS 2 新機能の細かい話5つ• watchOS-2-Sampler 実装にあたって気付いた細かい諸々について

- 2つのアセットカタログの 使い分け

- メディアデータの 保存場所

- WKAudioFilePlayer

- ウォッチ側 Bluetooth の (直接)利用

- Watch Connectivity のメッセージ送信可否の条件

• 『potatotips #18』での発表

• slideshare.net/t26v0748/uiux-watchos-2-3

• d.hatena.ne.jp/shu223/20150616/1434454680

Page 9: Core Graphics on watchOS 2

UI/UX に影響の大きい watchOS 2 の新機能

• watchOS 2 の数ある新機能の中で、UI/UX に影響の大きそうな機能を3

つ抜粋して紹介

• 『UI Crunch #5』というデザイナーさん、ディレクターさんも来る勉強会での発表

- (なのでコードは出てきません)

• http://www.slideshare.net/t26v0748/uiux-watchos-2-3

Page 10: Core Graphics on watchOS 2

Core Image の新機能

• iOS 9 の Core Image の新機能について紹介&デモ

- 文字認識

- 新フィルタ47種

• @『WWDC Afterparty Roppongi』

• slideshare.net/t26v0748/ios-9-core-image

• d.hatena.ne.jp/shu223/20150622/1434924215

Page 11: Core Graphics on watchOS 2

Audio Unit Extensions~オーディオエフェクトのアプリ間共有~

• iOS 9 で追加された Extension Point

• Audio Unit をアプリ間で共有できる

• @『WWDC2015報告共有会@ネクスト』

• www.slideshare.net/t26v0748/wwdc-next-201506232

• d.hatena.ne.jp/shu223/20150624/1435098847

Page 12: Core Graphics on watchOS 2

本題:

Core Graphics on

watchOS 2

※Appleの公開ドキュメントの範囲で発表します

Page 13: Core Graphics on watchOS 2

watchOS 1 をふりかえる

Page 14: Core Graphics on watchOS 2

watchOS 1 をふりかえる• Core Graphics は使えなかった

Page 15: Core Graphics on watchOS 2

watchOS 1 をふりかえる• Core Graphics は使えなかった

• Apple公式サンプルでは、360

個の連番pngを利用して

Circular Progress 的なUIを実現

『WatchKitを実際にさわってみてわかったこと』

Page 16: Core Graphics on watchOS 2

@watchOS 2

Page 17: Core Graphics on watchOS 2

@watchOS 2• Core Graphics がネイティブSDKに追加された

Page 18: Core Graphics on watchOS 2

@watchOS 2• Core Graphics がネイティブSDKに追加された

• Apple のWWDC動画やサンプル、GitHub・StackOverflow にも具体的なコードは見当たらず

Page 19: Core Graphics on watchOS 2

@watchOS 2• Core Graphics がネイティブSDKに追加された

• Apple のWWDC動画やサンプル、GitHub・StackOverflow にも具体的なコードは見当たらず

• 何ができて、何ができないのか? 試してみる

Page 20: Core Graphics on watchOS 2

Trial1 : Draw a line

Page 21: Core Graphics on watchOS 2

Trial1 : Draw a line

実行結果:<Error>: CGContextDrawPath: invalid context 0x0.

Page 22: Core Graphics on watchOS 2

Trial1 : Draw a line

実行結果:<Error>: CGContextDrawPath: invalid context 0x0.

→watchOS では、UIGraphicsGetCurrentContext() でグラフィックスコンテキストを取得できない?

Page 23: Core Graphics on watchOS 2

Trial2: Create a bitmap-based graphics context and draw lines

Page 24: Core Graphics on watchOS 2

Trial2: Create a bitmap-based graphics context and draw lines

Page 25: Core Graphics on watchOS 2

実行結果:うまくいった

※NDAに配慮しスクリーンショットは会場のみとします

Page 26: Core Graphics on watchOS 2

ここさえクリアできれば、大抵のことは可能

Page 27: Core Graphics on watchOS 2

Trial3: Draw using UIBezierPath※NDAに配慮しスクリーンショット

は会場のみとします

Page 28: Core Graphics on watchOS 2

Trial4: Draw from a SVG file

※ SVG to UIBezierPath の変換にはOSS『PocketSVG』を利用

※NDAに配慮しスクリーンショットは会場のみとします

Page 29: Core Graphics on watchOS 2

Trial5: Draw a gradation※NDAに配慮しスクリーンショット

は会場のみとします

Page 30: Core Graphics on watchOS 2

watchOS-2-Sampler

GitHub: shu223/watchOS-2-Sampler

Blog: watchOS 2 の新機能のサンプルコード集『watchOS-2-Sampler』

watchOS 2 新機能のサンプルコード集 - Accelerometer - Gyroscope - Pedometer - Heart Rate - Table Animations - Animated Properties - Draw Paths - Gradations - Audio Rec & Play - Picker Styles - Taptic Engine - Alert - Animation with Digital Crown - Interactive Messaging - Open System URL - Audio File Player

今回のサンプル

Page 31: Core Graphics on watchOS 2

何ができないのか?

Page 32: Core Graphics on watchOS 2

UIView とか CALayer に依存する処理は不可

Page 33: Core Graphics on watchOS 2

UIView とか CALayer に依存する処理は不可

例: スクリーンキャプチャ

Page 34: Core Graphics on watchOS 2

UIView とか CALayer に依存する処理は不可

例: スクリーンキャプチャ

Page 35: Core Graphics on watchOS 2

UIView とか CALayer に依存する処理は不可

例: スクリーンキャプチャ

Page 36: Core Graphics on watchOS 2

UIView とか CALayer に依存する処理は不可

例: スクリーンキャプチャ

UIView または CALayer オブジェクトの内容を描画する必要があるため watchOS では(いまのところ)利用不可

Page 37: Core Graphics on watchOS 2

「手書き」も不可• 自由なパスの描画は可能になったものの、タッチ位置を取得するAPIがまだ開放されていない

Page 38: Core Graphics on watchOS 2

キーパスアニメーションも不可

Page 39: Core Graphics on watchOS 2

キーパスアニメーションも不可• CAKeyframeAnimation を使うと、パスに沿ってオブジェクトをアニメーションさせるとか、生成したパス自体をアニメーションさせたりできる

Page 40: Core Graphics on watchOS 2

キーパスアニメーションも不可• CAKeyframeAnimation を使うと、パスに沿ってオブジェクトをアニメーションさせるとか、生成したパス自体をアニメーションさせたりできる

• こういうの →をやりたいときには必要

Page 41: Core Graphics on watchOS 2

キーパスアニメーションも不可• CAKeyframeAnimation を使うと、パスに沿ってオブジェクトをアニメーションさせるとか、生成したパス自体をアニメーションさせたりできる

• こういうの →をやりたいときには必要

• CALayer オブジェクトにアクセスできないので、addAnimation: できない。

Page 42: Core Graphics on watchOS 2

キーパスアニメーションも不可• CAKeyframeAnimation を使うと、パスに沿ってオブジェクトをアニメーションさせるとか、生成したパス自体をアニメーションさせたりできる

• こういうの →をやりたいときには必要

• CALayer オブジェクトにアクセスできないので、addAnimation: できない。

• すなわち現状では不可

Page 43: Core Graphics on watchOS 2

まとめ

Page 44: Core Graphics on watchOS 2

まとめ• watchOS 2 から Core Graphics を用いた動的な描画が可能になった

Page 45: Core Graphics on watchOS 2

まとめ• watchOS 2 から Core Graphics を用いた動的な描画が可能になった

• ビットマップコンテキスト上に描画し、UIImage を生成してそれを表示する

Page 46: Core Graphics on watchOS 2

まとめ• watchOS 2 から Core Graphics を用いた動的な描画が可能になった

• ビットマップコンテキスト上に描画し、UIImage を生成してそれを表示する

• この制約の範囲内であれば、結構いろんなことができる

Page 47: Core Graphics on watchOS 2

まとめ• watchOS 2 から Core Graphics を用いた動的な描画が可能になった

• ビットマップコンテキスト上に描画し、UIImage を生成してそれを表示する

• この制約の範囲内であれば、結構いろんなことができる

• CALayer オブジェクトにアクセスできないので、スクリーンキャプチャやキーパスアニメーションは不可