インストール
まずはBubbleWrap
をインストール。
Gemfile
gem 'bubble-wrap'
Rakefile
require 'bubble-wrap'
Bundle.require
bundle install --path vendor/bundle
使い方
スワイプの検知
スワイプを検知してみる。
方法は指定したジェスチャーにブロックを渡すだけ。
スワイプの方向を指定したい場合は戻り値のdirection
プロパティで指定する。
@left_swipe = @main_text.when_swiped do
p 'swipe left.'
end
@left_swipe.direction = UISwipeGestureRecognizerDirectionLeft
@right_swipe = @main_text.when_swiped do
p 'swipe right.'
end
@right_swipe.direction = UISwipeGestureRecognizerDirectionRight
# 上はUISwipeGestureRecognizerDirectionUp
# 下はUISwipeGestureRecognizerDirectionDown
タップの検知
# 2本指タップ
@two_finger_tap = @main_text.when_tapped do
p 'two finger.'
end
@two_finger_tap.numberOfTouchesRequired = 2
# ダブルタップ
@double_tap = @main_text.when_tapped do
p 'double tap.'
end
@double_tap.numberOfTapsRequired = 2
検知できるジェスチャー
- when_tapped
- when_pinched
- when_rotated
- when_swiped
- when_panned
- when_pressed
注意点
GitHubのページにあるサンプルではwhenTapped
とあるけど使うと古いからwhen_tapped
を使えとコンソールに出力される。
参考
- rubymotion/BubbleWrap · GitHub
- iPhone開発 スワイプイベントの設定 UISwipeGestureRecognizer ios 逆引き サンプル | Linux & App Labs By pt106
全ソース
rubymotion-samples/GestureByBubbleWrap at master · toshinori/rubymotion-samples · GitHub