Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ペダルのある生活 / The Pedal

Hiron
April 27, 2018

ペダルのある生活 / The Pedal

Mobile Act OSAKA #4で発表したスライドです。

Hiron

April 27, 2018
Tweet

More Decks by Hiron

Other Decks in Programming

Transcript

  1. UIKeyCommandを返す class ViewController: UIViewController { override var canBecomeFirstResponder: Bool {

    return true } override var keyCommands: [UIKeyCommand]? { return [ UIKeyCommand(input: UIKeyInputUpArrow, modifierFlags: [], action: #selector(pageUp)), UIKeyCommand(input: UIKeyInputDownArrow, modifierFlags: [], action: #selector(pageDown)), UIKeyCommand(input: UIKeyInputLeftArrow, modifierFlags: [], action: #selector(pageUp)), UIKeyCommand(input: UIKeyInputRightArrow, modifierFlags: [], action: #selector(pageDown)), ] } @objc func pageDown() { /* ࣍ͷϖʔδ΁ */ } @objc func pageUp() { /* લͷϖʔδ΁ */ } }
  2. PageUp、PageDownは? • APIで定義されていない • Stack Overflowに答えがあった(*) - 文字列 "UIKeyInputPageUp", "UIKeyInputPageDown"

    - Undocumented APIの使用になるかどうかは
 知らんけど * https://stackoverflow.com/a/44321674/4313724 (たぶん大丈夫。知らんけど)
  3. UIKeyCommandを返す override var keyCommands: [UIKeyCommand]? { return [ UIKeyCommand(input: UIKeyInputUpArrow,

    modifierFlags: [], action: #selector(pageUp)), UIKeyCommand(input: UIKeyInputDownArrow, modifierFlags: [], action: #selector(pageDown)), UIKeyCommand(input: UIKeyInputLeftArrow, modifierFlags: [], action: #selector(pageUp)), UIKeyCommand(input: UIKeyInputRightArrow, modifierFlags: [], action: #selector(pageDown)), UIKeyCommand(input: "UIKeyInputPageUp", modifierFlags: [], action: #selector(pageUp)), UIKeyCommand(input: "UIKeyInputPageDown", modifierFlags: [], action: #selector(pageDown)), ] }
  4. ハードウェアキーボード対応(Android) class MainActivity : AppCompatActivity() { override fun onKeyDown(keyCode: Int,

    event: KeyEvent?): Boolean { when (keyCode) { KeyEvent.KEYCODE_DPAD_UP, KeyEvent.KEYCODE_DPAD_LEFT, KeyEvent.KEYCODE_PAGE_UP -> { pageDown() return true } KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_PAGE_DOWN -> { pageUp() return true } else -> { return super.onKeyDown(keyCode, event) } } } private fun pageDown() { /* ࣍ͷϖʔδ΁ */ } private fun pageUp() { /* લͷϖʔδ΁ */ } }