LoginSignup
6
6

More than 5 years have passed since last update.

Apple Watch テキスト入力

Last updated at Posted at 2015-07-18

watchOS によるテキスト入力

Apple Watch では、物理キーボードやタッチパネルからのキーボード入力は行うことができません。

そのため、Apple Watch では定型文を用意しユーザーに選んでもらうことで文字を入力します。
また、定型文に存在しない文字も入力したい場合も必ず存在します。
そういった場合は、音声入力機能(Siri)を利用することで自由自在に文章を入力すことが可能です。

WKTextInputMode

Apple Watch でのテキスト入力方法を決める列挙型

enum WKTextInputMode : Int {

    case Plain // text (no emoji) from dictation + suggestions
    case AllowEmoji // text plus non-animated emoji from dictation + suggestions
    case AllowAnimatedEmoji // all text, animated emoji (GIF data)
}
  • Plain : 音声+定型文
  • AllowEmoji : 絵文字+音声+定型文
  • AllowAnimatedEmoji : アニメーション絵文字+音声+定型文

presentTextInputControllerWithSuggestions

Apple Watch の標準入力インターフェースを表示させる

func presentTextInputControllerWithSuggestions(suggestions: [String]?, allowedInputMode inputMode: WKTextInputMode, completion: ([AnyObject]?) -> Void)
 // results is nil if cancelled

  • suggestions: [String]? : 定型文として表示する文字列を配列で渡す
  • inputMode: WKTextInputMode : 入力インターフェイスを設定する
  • completion: ([AnyObject]?) -> Void) : ユーザーが入力した値が、配列の中に格納されて呼び出される

dismissTextInputController

表示されている Apple Watch の標準入力インターフェイスを消す

func dismissTextInputController()

使用例

let suggestions: Array<String>! = ["はい、なんでしょう?", "今、向かっています。","わかりました。"]
self.presentTextInputControllerWithSuggestions(suggestions, allowedInputMode: .Plain) { (objects: [AnyObject]?) -> Void in
            // 入力されたテキスト内容を処理する
}

...
self.dismissTextInputController()

IMG_0026.jpg

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6