Class: MotionWiretap::WiretapControl

Inherits:
WiretapView show all
Defined in:
lib/motion-wiretap/ios/wiretap_ios.rb

Instance Attribute Summary

Attributes inherited from WiretapKvo

#property

Attributes inherited from WiretapTarget

#target

Attributes inherited from Wiretap

#value

Instance Method Summary collapse

Methods inherited from WiretapView

#handle_gesture

Methods inherited from WiretapKvo

#bind_to, #observeValueForKeyPath

Methods inherited from Wiretap

#and_then, #cancel!, #combine, #dealloc, #enqueue, #filter, #listen, #map, #on_error, #queue, #reduce, #trigger_changed, #trigger_changed_on, #trigger_completed, #trigger_completed_on, #trigger_error, #trigger_error_on

Constructor Details

#initialize(target, &block) ⇒ WiretapControl

Returns a new instance of WiretapControl.



56
57
58
59
# File 'lib/motion-wiretap/ios/wiretap_ios.rb', line 56

def initialize(target, &block)
  super
  @control_events = []
end

Instance Method Details

#handle_event(event) ⇒ Object



79
80
81
# File 'lib/motion-wiretap/ios/wiretap_ios.rb', line 79

def handle_event(event)
  trigger_changed(event)
end

#on(control_event, options = {}, &block) ⇒ Object

control_event can be any UIControlEventConstant, or any symbol found in wiretap_control_events.rb, or an array of UIControlEventConstants or symbols. Since UIView implements ‘on` to accept a gesture, this method calls `super` when the symbol isn’t a control



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/motion-wiretap/ios/wiretap_ios.rb', line 65

def on(control_event, options={}, &block)
  begin
    control_event = ControlEvents.convert(control_event)
    self.target.addTarget(self, action: 'handle_event:', forControlEvents: control_event)
    @control_events << control_event
  rescue ControlEventNotFound
    super(control_event, options, &block)
  else
    super(nil, options, &block)
  end

  return self
end

#teardownObject



83
84
85
86
87
88
89
# File 'lib/motion-wiretap/ios/wiretap_ios.rb', line 83

def teardown
  remove_event = (-> (event) {
    self.target.removeTarget(self, action: 'handle_event:', forControlEvents: event)
  }).weak!
  @control_events.each(&remove_event)
  super
end