Class: RubyMotionQuery::Event
- Inherits:
-
Object
- Object
- RubyMotionQuery::Event
- Defined in:
- motion/ruby_motion_query/event.rb
Constant Summary
- CONTROL_EVENTS =
{ touch: UIControlEventTouchUpInside, touch_up: UIControlEventTouchUpInside, touch_down: UIControlEventTouchDown, touch_start: UIControlEventTouchDown | UIControlEventTouchDragEnter, touch_stop: UIControlEventTouchUpInside | UIControlEventTouchCancel | UIControlEventTouchDragExit, change: UIControlEventValueChanged | UIControlEventEditingChanged, touch_down_repeat: UIControlEventTouchDownRepeat, touch_drag_inside: UIControlEventTouchDragInside, touch_drag_outside: UIControlEventTouchDragOutside, touch_drag_enter: UIControlEventTouchDragEnter, touch_drag_exit: UIControlEventTouchDragExit, touch_up_inside: UIControlEventTouchUpInside, touch_up_outside: UIControlEventTouchUpOutside, touch_cancel: UIControlEventTouchCancel, value_changed: UIControlEventValueChanged, editing_did_begin: UIControlEventEditingDidBegin, editing_changed: UIControlEventEditingChanged, editing_did_change: UIControlEventEditingChanged, editing_did_end: UIControlEventEditingDidEnd, editing_did_endonexit: UIControlEventEditingDidEndOnExit, all_touch: UIControlEventAllTouchEvents, all_editing: UIControlEventAllEditingEvents, application: UIControlEventApplicationReserved, system: UIControlEventSystemReserved, all: UIControlEventAllEvents }
- VIEW_GESTURES =
{ tap: UITapGestureRecognizer, pinch: UIPinchGestureRecognizer, rotate: UIRotationGestureRecognizer, swipe: UISwipeGestureRecognizer, pan: UIPanGestureRecognizer, long_press: UILongPressGestureRecognizer }
Instance Attribute Summary (collapse)
-
- (Object) block
Returns the value of attribute block.
-
- (Object) event
Returns the value of attribute event.
-
- (Object) gesture
Returns the value of attribute gesture.
-
- (Object) recognizer
Returns the value of attribute recognizer.
-
- (Object) sdk_event_or_recognizer
Returns the value of attribute sdk_event_or_recognizer.
-
- (Object) sender
Returns the value of attribute sender.
Instance Method Summary (collapse)
- - (Boolean) gesture?
- - (Object) handle_gesture_or_event
-
- (Event) initialize(sender, event, block)
constructor
A new instance of Event.
- - (Object) location
- - (Object) location_in(view)
- - (Object) remove
- - (Object) set_options(opts)
Constructor Details
- (Event) initialize(sender, event, block)
Returns a new instance of Event
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'motion/ruby_motion_query/event.rb', line 5 def initialize(sender, event, block) if @sdk_event_or_recognizer = VIEW_GESTURES[event] @gesture = true elsif sender.is_a?(UIControl) @gesture = false @sdk_event_or_recognizer = CONTROL_EVENTS[event] end if @sdk_event_or_recognizer @sender = sender @event = event @block = block if @gesture @recognizer = @sdk_event_or_recognizer.alloc.initWithTarget(self, action: :handle_gesture_or_event) @sender.addGestureRecognizer(@recognizer) else @sender.addTarget(self, action: :handle_gesture_or_event, forControlEvents: @sdk_event_or_recognizer) end else raise "[RMQ Error] Invalid event or gesture or invalid sender (#{event}). Example of use: button.on(:touch) { my_code }" end end |
Instance Attribute Details
- (Object) block
Returns the value of attribute block
3 4 5 |
# File 'motion/ruby_motion_query/event.rb', line 3 def block @block end |
- (Object) event
Returns the value of attribute event
3 4 5 |
# File 'motion/ruby_motion_query/event.rb', line 3 def event @event end |
- (Object) gesture
Returns the value of attribute gesture
3 4 5 |
# File 'motion/ruby_motion_query/event.rb', line 3 def gesture @gesture end |
- (Object) recognizer
Returns the value of attribute recognizer
3 4 5 |
# File 'motion/ruby_motion_query/event.rb', line 3 def recognizer @recognizer end |
- (Object) sdk_event_or_recognizer
Returns the value of attribute sdk_event_or_recognizer
3 4 5 |
# File 'motion/ruby_motion_query/event.rb', line 3 def sdk_event_or_recognizer @sdk_event_or_recognizer end |
- (Object) sender
Returns the value of attribute sender
3 4 5 |
# File 'motion/ruby_motion_query/event.rb', line 3 def sender @sender end |
Instance Method Details
- (Boolean) gesture?
62 63 64 |
# File 'motion/ruby_motion_query/event.rb', line 62 def gesture? @gesture end |
- (Object) handle_gesture_or_event
29 30 31 32 33 34 35 36 37 38 |
# File 'motion/ruby_motion_query/event.rb', line 29 def handle_gesture_or_event case @block.arity when 2 @block.call(@sender, self) when 1 @block.call(@sender) else @block.call end end |
- (Object) location
66 67 68 69 70 71 72 |
# File 'motion/ruby_motion_query/event.rb', line 66 def location if gesture? @recognizer.locationInView(@sender) else @sender.convertRect(@sender.bounds, toView: nil).origin end end |
- (Object) location_in(view)
74 75 76 77 78 79 80 |
# File 'motion/ruby_motion_query/event.rb', line 74 def location_in(view) if gesture? @recognizer.locationInView(view) else @sender.convertRect(@sender.bounds, toView: view).origin end end |
- (Object) remove
82 83 84 85 86 87 88 89 90 |
# File 'motion/ruby_motion_query/event.rb', line 82 def remove if @sender if self.gesture? @sender.removeGestureRecognizer(@recognizer) else @sender.removeTarget(self, action: :handle_gesture_or_event, forControlEvents: @sdk_event_or_recognizer) end end end |
- (Object) set_options(opts)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'motion/ruby_motion_query/event.rb', line 40 def (opts) if gesture? @recognizer.tap do |o| o.cancelsTouchesInView = opts[:cancels_touches_in_view] if opts.include?(:cancels_touches_in_view) o.delegate = opts[:delegate] if opts.include?(:delegate) o.numberOfTapsRequired = opts[:taps_required] if opts.include?(:taps_required) o.numberOfTouchesRequired = opts[:fingers_required] if opts.include?(:fingers_required) o.maximumNumberOfTouches = opts[:maximum_number_of_touches] if opts.include?(:maximum_number_of_touches) o.minimumNumberOfTouches = opts[:minimum_number_of_touches] if opts.include?(:minimum_number_of_touches) o.allowableMovement = opts[:allowable_movement] if opts.include?(:allowable_movement) o.minimumPressDuration = opts[:minimum_press_duration] if opts.include?(:minimum_press_duration) o.direction = opts[:direction] if opts.include?(:direction) o.rotation = opts[:rotation] if opts.include?(:rotation) o.scale = opts[:scale] if opts.include?(:scale) if opts.include?(:init) opts[:init].call(@recognizer) end end end end |