sugarcube 0.13.4 → 0.13.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -39,6 +39,14 @@ decision was made to offer it to the rubymotion community, in the spirit of
39
39
  open-source and collaboration. It is a great compliment to [teacup][],
40
40
  especially when paired with [sweettea][]!
41
41
 
42
+ Documentation
43
+ =============
44
+
45
+ A work in progress. This README is the best source, but I am trying to be more
46
+ diligent about adding Yard documentation, which is available here:
47
+
48
+ <http://rubydoc.info/gems/sugarcube/latest>
49
+
42
50
 
43
51
  Installation
44
52
  ============
@@ -670,6 +678,13 @@ These accept completion blocks:
670
678
  ```ruby
671
679
  present_modal(view_ctlr) { puts "here!" }
672
680
  dismiss_modal { puts "gone!" }
681
+ ```
682
+
683
+ If you like these methods, but you want to specify the reciever, they are
684
+ re-defined on `UIViewController` for this purpose:
685
+
686
+ ```ruby
687
+ controller.present_modal(other_controller) { puts "presented" }
673
688
  ```
674
689
 
675
690
  UINavigationController
@@ -3,15 +3,39 @@
3
3
  # changing it to suit my needs, and offering it here
4
4
  class UIView
5
5
 
6
- # a generic gesture adder, but using sugarcube_add_gesture, which handles the block
6
+ # A generic gesture adder, but accepts a block like the other gesture methods
7
+ # @yield [recognizer] Handles the gesture event, and passes the recognizer instance to the block.
8
+ # @param options [Hash] method/value pairs to call on the gesture.
9
+ # @overload on_gesture(recognizer)
10
+ # Adds the gesture to the view, and yields the block when the gesture is recognized
11
+ # @overload on_gesture(recognizer_class)
12
+ # Instantiates a gesture and adds it to the view.
13
+ # @example Using a UIGestureRecognizer class
14
+ # view.on_gesture(UISwipeGestureRecognizer, direction: UISwipeGestureRecognizerDirectionLeft) { puts "swiped left" }
15
+ # @example Using a UIGestureRecognizer instance
16
+ # gesture = UISwipeGestureRecognizer
17
+ # gesture.direction = UISwipeGestureRecognizerDirectionLeft
18
+ # view.on_gesture(gesture) { puts "swiped left" }
7
19
  def on_gesture(klass, options={}, &proc)
8
- recognizer = klass.alloc.initWithTarget(self, action:'sugarcube_handle_gesture:')
20
+ if klass.is_a? UIGestureRecognizer
21
+ recognizer = klass
22
+ recognizer.addTarget(self, action:'sugarcube_handle_gesture:')
23
+ else
24
+ recognizer = klass.alloc.initWithTarget(self, action:'sugarcube_handle_gesture:')
25
+ end
26
+
9
27
  options.each do |method, value|
10
28
  recognizer.send(method, value)
11
29
  end
12
30
  sugarcube_add_gesture(proc, recognizer)
13
31
  end
14
32
 
33
+ # @yield [recognizer] Handles the gesture event, and passes the recognizer instance to the block.
34
+ # @overload on_tap(taps)
35
+ # @param taps [Fixnum] Number of taps
36
+ # @overload on_tap(options)
37
+ # @option options [Fixnum] :taps Number of taps before gesture is recognized
38
+ # @option options [Fixnum] :fingers Number of fingers before gesture is recognized
15
39
  def on_tap(taps_or_options=nil, &proc)
16
40
  taps = nil
17
41
  fingers = nil
@@ -31,16 +55,24 @@ class UIView
31
55
  sugarcube_add_gesture(proc, recognizer)
32
56
  end
33
57
 
58
+ # @yield [recognizer] Handles the gesture event, and passes the recognizer instance to the block.
34
59
  def on_pinch(&proc)
35
60
  recognizer = UIPinchGestureRecognizer.alloc.initWithTarget(self, action:'sugarcube_handle_gesture:')
36
61
  sugarcube_add_gesture(proc, recognizer)
37
62
  end
38
63
 
64
+ # @yield [recognizer] Handles the gesture event, and passes the recognizer instance to the block.
39
65
  def on_rotate(&proc)
40
66
  recognizer = UIRotationGestureRecognizer.alloc.initWithTarget(self, action:'sugarcube_handle_gesture:')
41
67
  sugarcube_add_gesture(proc, recognizer)
42
68
  end
43
69
 
70
+ # @yield [recognizer] Handles the gesture event, and passes the recognizer instance to the block.
71
+ # @overload on_swipe(taps)
72
+ # @param direction [Fixnum] Direction of swipe
73
+ # @overload on_swipe(options)
74
+ # @option options [Fixnum] :fingers Number of fingers before gesture is recognized
75
+ # @option options [Fixnum, Symbol] :direction Direction of swipe, as a UISwipeGestureRecognizerDirection constant or a symbol (`:left, :right, :up, :down`)
44
76
  def on_swipe(direction_or_options=nil, &proc)
45
77
  direction = UISwipeGestureRecognizerDirectionRight
46
78
  fingers = nil
@@ -71,6 +103,13 @@ class UIView
71
103
  sugarcube_add_gesture(proc, recognizer)
72
104
  end
73
105
 
106
+ # @yield [recognizer] Handles the gesture event, and passes the recognizer instance to the block.
107
+ # @overload on_tap(taps)
108
+ # @param taps [Fixnum] Number of taps
109
+ # @overload on_tap(options)
110
+ # @option options [Fixnum] :min_fingers Minimum umber of fingers for gesture to be recognized
111
+ # @option options [Fixnum] :max_fingers Maximum number of fingers for gesture to be recognized
112
+ # @option options [Fixnum] :fingers If min_fingers or max_fingers is not assigned, this will be the default.
74
113
  def on_pan(fingers_or_options=nil, &proc)
75
114
  fingers = nil
76
115
  min_fingers = nil
@@ -80,15 +119,29 @@ class UIView
80
119
  if fingers_or_options.is_a? Hash
81
120
  fingers = fingers_or_options[:fingers] || fingers
82
121
  min_fingers = fingers_or_options[:min_fingers] || min_fingers
83
- max_fingers = fingers_or_options[:max_fingers] || max_fingers else
122
+ max_fingers = fingers_or_options[:max_fingers] || max_fingers
123
+ else
84
124
  fingers = fingers_or_options
85
125
  end
86
126
  end
87
127
 
128
+ # if fingers is assigned, but not min/max, assign it as a default
129
+ min_fingers ||= fingers
130
+ max_fingers ||= fingers
131
+
88
132
  recognizer = UIPanGestureRecognizer.alloc.initWithTarget(self, action:'sugarcube_handle_gesture:')
133
+ recognizer.maximumNumberOfTouches = min_fingers if min_fingers
134
+ recognizer.minimumNumberOfTouches = max_fingers if max_fingers
89
135
  sugarcube_add_gesture(proc, recognizer)
90
136
  end
91
137
 
138
+ # @yield [recognizer] Handles the gesture event, and passes the recognizer instance to the block.
139
+ # @overload on_press(duration)
140
+ # @param duration [Fixnum] How long in seconds before gesture is recognized
141
+ # @overload on_tap(options)
142
+ # @option options [Fixnum] :duration How long in seconds before gesture is recognized
143
+ # @option options [Fixnum] :taps Number of taps before gesture is recognized
144
+ # @option options [Fixnum] :fingers Number of fingers before gesture is recognized
92
145
  def on_press(duration_or_options=nil, &proc)
93
146
  duration = nil
94
147
  taps = nil
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.13.4'
2
+ Version = '0.13.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.4
4
+ version: 0.13.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: