Más contenido relacionado
Similar a シェイクを検知して学ぼう、モーションイベント! (20)
Más de Kanako Kobayashi (7)
シェイクを検知して学ぼう、モーションイベント!
- 2. • WordPressもくもく倶楽部@Co-Edoもやってます。
• Ruby / Ruby on Rails ビギナーズ倶楽部@Co-Edoやってます( ́ ▽ ` )ノ
• スマホアプリ開発初心者な、アプリケーションエンジニア(Rails / LAMP / Java / Oracle)
Self-Intoroduction
http://ror-beginners.doorkeeper.jp/
http://wp-moku.doorkeeper.jp/
- 10. @IBOutlet weak var countLabel: UILabel!
var cnt = 0
override func motionBegan(motion: UIEventSubtype, withEvent event: UIEvent) {
if event.type == UIEventType.Motion && event.subtype == UIEventSubtype.MotionShake {
// シェイク動作始まり時の処理
// 今回は特に処理を入れていません。
}
}
override func motionEnded(motion: UIEventSubtype, withEvent event: UIEvent) {
if event.type == UIEventType.Motion && event.subtype == UIEventSubtype.MotionShake {
// シェイク動作終了時の処理
cnt++
countLabel.text = cnt.description
}
}
override func motionCancelled(motion: UIEventSubtype, withEvent event: UIEvent) {
// モーションイベントをキャンセルしたとき対処
// イベントがキャンセルされるのは、シェイクモーションが割り込まれたとき、
// あるいは(シェイクがあまりに長く続くなどのため)モーションが有効でないとiOSが判断したときです。
countLabel.text = "NG"
}
3-2)モーションイベントの実装方法!
DEMOアプリのコード