Class: UIWindow

Inherits:
Object
  • Object
show all
Defined in:
lib/motion_egg/uiwindow.rb

Instance Method Summary collapse

Instance Method Details

#add_egg(options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/motion_egg/uiwindow.rb', line 3

def add_egg(options = {})

  # Easter egg workhorse
  @egg = Egg.new options

  #left
  @swipe_gesture_left = UISwipeGestureRecognizer.alloc.initWithTarget(self, action:"handle_swipe:")
  @swipe_gesture_left.direction = UISwipeGestureRecognizerDirectionLeft 
  @swipe_gesture_left.numberOfTouchesRequired = @egg.number_touches
  self.addGestureRecognizer(@swipe_gesture_left)

  #right
  @swipe_gesture_right = UISwipeGestureRecognizer.alloc.initWithTarget(self, action:"handle_swipe:")
  @swipe_gesture_right.direction = UISwipeGestureRecognizerDirectionRight
  @swipe_gesture_right.numberOfTouchesRequired = @egg.number_touches
  self.addGestureRecognizer(@swipe_gesture_right)

  #up
  @swipe_gesture_up = UISwipeGestureRecognizer.alloc.initWithTarget(self, action:"handle_swipe:")
  @swipe_gesture_up.direction = UISwipeGestureRecognizerDirectionUp
  @swipe_gesture_up.numberOfTouchesRequired = @egg.number_touches
  self.addGestureRecognizer(@swipe_gesture_up)    

  #down
  @swipe_gesture_down = UISwipeGestureRecognizer.alloc.initWithTarget(self, action:"handle_swipe:")
  @swipe_gesture_down.direction = UISwipeGestureRecognizerDirectionDown
  @swipe_gesture_down.numberOfTouchesRequired = @egg.number_touches
  self.addGestureRecognizer(@swipe_gesture_down)  
end

#handle_swipe(sender) ⇒ Object

each recognizer should have a direction, but you can send them all to the same function!



34
35
36
# File 'lib/motion_egg/uiwindow.rb', line 34

def handle_swipe(sender)
  @egg.add_code(sender.direction)
end