LoginSignup
3
3

More than 5 years have passed since last update.

BubbleWrapでジェスチャーを検知する

Posted at

インストール

まずは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-samples/GestureByBubbleWrap at master · toshinori/rubymotion-samples · GitHub

3
3
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
3
3