sugarcube 1.3.11 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -71,27 +71,6 @@ Installation
71
71
  # in terminal
72
72
  $ bundle install
73
73
 
74
- Memory Management
75
- =================
76
-
77
- There are some very convenient helper methods around touches and gestures, but
78
- they come with an unfortunate side effect. These helpers accept a block, but
79
- that block retains a reference to the object it was created in, which is usually
80
- a controller.
81
-
82
- ```ruby
83
- # ... somewhere in a controller
84
- button.on :touch do
85
- # handle touch event
86
- self.do_something! # <= the block retains 'self' so that this handler will
87
- # work, even if the controller is released.
88
- end
89
- ```
90
-
91
- To fix this, you need to call `sugarcube_cleanup` when a controller is "going
92
- away". Another option is to add/remove button/gesture callbacks when the view
93
- appears, and remove them when it disappears.
94
-
95
74
  Packages
96
75
  ========
97
76
 
@@ -389,9 +368,19 @@ view.on_pan(2) # minimum and maximum fingers required
389
368
  view.on_pan(fingers: 2)
390
369
  view.on_pan(min_fingers: 2, max_fingers: 3)
391
370
 
392
- view.on_press # use system defaults
371
+ # `on_press` is a continuous event (it uses UILongPressGestureRecognizer), so
372
+ # you need to check the `gesture`:
373
+ view.on_press do |gesture|
374
+ if gesture.state == UIGestureRecognizerStateBegan
375
+ # handle press
376
+ end
377
+ end
393
378
  view.on_press(1.5) # duration
394
379
  view.on_press(duration: 1.5, taps: 1, fingers: 1)
380
+
381
+ # this version is only fired when the long-press begins; this is *probably* more
382
+ # useful to you:
383
+ view.on_press_begin do ... end
395
384
  ```
396
385
 
397
386
  Notifications
@@ -672,6 +661,7 @@ UIButton.info_light => UIButton.buttonWithType(:info_light.uibuttontype)
672
661
  UIButton.info_dark => UIButton.buttonWithType(:info_dark.uibuttontype)
673
662
  UIButton.contact => UIButton.buttonWithType(:contact.uibuttontype)
674
663
  UIButton.contact_add => UIButton.buttonWithType(:contact_add.uibuttontype)
664
+ UIButton.system => UIButton.buttonWithType(:system.uibuttontype)
675
665
  ```
676
666
 
677
667
  ###### UITableView
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '1.3.11'
2
+ Version = '1.4.0'
3
3
  end
@@ -291,6 +291,43 @@ class UIView
291
291
  return self
292
292
  end
293
293
 
294
+ # moves the view off screen, then animates it back on screen. The movement
295
+ # off screen happens immediately, so if you provide a `delay:` option, it will
296
+ # only affect the movement back on screen.
297
+ def slide_from(direction, options={}, more_options={}, &after)
298
+ if options.is_a? Numeric
299
+ size = options
300
+ options = more_options
301
+ else
302
+ size = options[:size]
303
+ end
304
+
305
+ options[:from_current] = false unless options.key?(:from_current)
306
+ window_size = UIApplication.sharedApplication.windows[0].frame.size
307
+
308
+ case direction
309
+ when :left
310
+ size ||= window_size.width
311
+ self.center = CGPoint.new(self.center.x - size, self.center.y)
312
+ self.delta_to([size, 0], options, &after)
313
+ when :right
314
+ size ||= window_size.width
315
+ self.center = CGPoint.new(self.center.x + size, self.center.y)
316
+ self.delta_to([-size, 0], options, &after)
317
+ when :top, :up
318
+ size ||= window_size.height
319
+ self.center = CGPoint.new(self.center.x, self.center.y - size)
320
+ self.delta_to([0, size], options, &after)
321
+ when :bottom, :down
322
+ size ||= window_size.height
323
+ self.center = CGPoint.new(self.center.x, self.center.y + size)
324
+ self.delta_to([0, -size], options, &after)
325
+ else
326
+ raise "Unknown direction #{direction.inspect}"
327
+ end
328
+ return self
329
+ end
330
+
294
331
  # Vibrates the target. You can trick this thing out to do other effects, like:
295
332
  # @example
296
333
  # # wiggle
@@ -8,6 +8,10 @@ class NSURL
8
8
  UIApplication.sharedApplication.canOpenURL(self)
9
9
  end
10
10
 
11
+ def nsurl
12
+ self
13
+ end
14
+
11
15
  def nsurlrequest
12
16
  NSURLRequest.requestWithURL(self)
13
17
  end
@@ -175,6 +175,29 @@ class UIView
175
175
  sugarcube_add_gesture(proc, recognizer)
176
176
  end
177
177
 
178
+ def on_press_begin(duration_or_options=nil, &proc)
179
+ duration = nil
180
+ taps = nil
181
+ fingers = nil
182
+
183
+ if duration_or_options
184
+ if duration_or_options.is_a? Hash
185
+ duration = duration_or_options[:duration] || duration
186
+ taps = duration_or_options[:taps] || taps
187
+ fingers = duration_or_options[:fingers] || fingers
188
+ else
189
+ duration = duration_or_options
190
+ end
191
+ end
192
+
193
+ recognizer = UILongPressGestureRecognizer.alloc.initWithTarget(self, action:'sugarcube_handle_gesture_long_press_on_begin:')
194
+ recognizer.minimumPressDuration = duration if duration
195
+ recognizer.numberOfTapsRequired = taps if taps
196
+ recognizer.numberOfTouchesRequired = fingers if fingers
197
+ sugarcube_add_gesture(proc, recognizer)
198
+ end
199
+
200
+
178
201
  private
179
202
  def sugarcube_handle_gesture(recognizer)
180
203
  handler = @sugarcube_recognizers[recognizer]
@@ -184,6 +207,16 @@ private
184
207
  handler.call(recognizer)
185
208
  end
186
209
  end
210
+ def sugarcube_handle_gesture_long_press_on_begin(recognizer)
211
+ if recognizer.state==UIGestureRecognizerStateBegan
212
+ handler = @sugarcube_recognizers[recognizer]
213
+ if handler.arity == 0
214
+ handler.call
215
+ else
216
+ handler.call(recognizer)
217
+ end
218
+ end
219
+ end
187
220
 
188
221
  # Adds the recognizer and keeps a strong reference to the Proc object.
189
222
  def sugarcube_add_gesture(proc, recognizer)
@@ -34,7 +34,7 @@ class NSDate
34
34
  NSDate.new.delta(days: -1).start_of_day
35
35
  end
36
36
 
37
- def string_with_style(date_style=NSDateFormatterMediumStyle,time_style=NSDateFormatterNoStyle)
37
+ def string_with_style(date_style=NSDateFormatterMediumStyle, time_style=NSDateFormatterNoStyle)
38
38
  date_formatter = NSDateFormatter.new
39
39
  date_style = date_style.nsdatestyle if date_style.is_a? Symbol
40
40
  time_style = time_style.nsdatestyle if time_style.is_a? Symbol
data/spec/nsurl_spec.rb CHANGED
@@ -4,6 +4,11 @@ describe "NSURL" do
4
4
  'test'.nsurl.respond_to?(:open).should == true
5
5
  end
6
6
 
7
+ it "should have a method #nsurl" do
8
+ url = 'https://github.com'.nsurl
9
+ url.nsurl.should == url
10
+ end
11
+
7
12
  it "should have a method #can_open?" do
8
13
  'https://github.com'.nsurl.can_open?.should == true
9
14
  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: 1.3.11
4
+ version: 1.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-12-13 00:00:00.000000000 Z
15
+ date: 2014-01-24 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description: ! '== Description
18
18