Class: UIView
- Inherits:
-
Object
- Object
- UIView
- Defined in:
- lib/sugarcube/uiview.rb,
lib/sugarcube/to_s/uiview.rb
Instance Method Summary collapse
- #<<(view) ⇒ Object
- #_after_proc(after) ⇒ Object
- #delta_to(delta, options = {}, &after) ⇒ Object
- #fade_in(options = {}, &after) ⇒ Object
-
#fade_out(options = {}, &after) ⇒ Object
If options is a Numeric, it is used as the duration.
- #hide ⇒ Object
- #move_to(position, options = {}, &after) ⇒ Object
- #shake(options = {}) ⇒ Object
- #show ⇒ Object
- #slide(direction, options = {}, &after) ⇒ Object
- #to_s ⇒ Object
Instance Method Details
#<<(view) ⇒ Object
3 4 5 |
# File 'lib/sugarcube/uiview.rb', line 3 def <<(view) self.addSubview view end |
#_after_proc(after) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/sugarcube/uiview.rb', line 17 def _after_proc(after) after ? proc { |finished| if after.arity == 0 after.call else after.call(finished) end } : nil end |
#delta_to(delta, options = {}, &after) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/sugarcube/uiview.rb', line 84 def delta_to(delta, ={}, &after) f = self.frame delta = SugarCube::CoreGraphics::Point(delta) position = SugarCube::CoreGraphics::Point(f.origin) move_to(position + delta, , &after) self end |
#fade_in(options = {}, &after) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sugarcube/uiview.rb', line 50 def fade_in(={}, &after) if .is_a? Numeric duration = = {} else duration = [:duration] || 0.3 end [:opacity] = 1.0 fade_out(, &after) end |
#fade_out(options = {}, &after) ⇒ Object
If options is a Numeric, it is used as the duration. Otherwise, duration is an option, and defaults to 0.3. All the transition methods work this way.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sugarcube/uiview.rb', line 30 def fade_out(={}, &after) if .is_a? Numeric duration = = {} else duration = [:duration] || 0.3 end after = _after_proc(after) UIView.animateWithDuration(duration, delay: [:delay] || 0, options: [:options] || UIViewAnimationOptionCurveLinear, animations: proc{ self.layer.opacity = [:opacity] || 0 }, completion:after ) self end |
#hide ⇒ Object
12 13 14 15 |
# File 'lib/sugarcube/uiview.rb', line 12 def hide self.hidden = true self end |
#move_to(position, options = {}, &after) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/sugarcube/uiview.rb', line 62 def move_to(position, ={}, &after) if .is_a? Numeric duration = = {} else duration = [:duration] || 0.3 end after = _after_proc(after) UIView.animateWithDuration(duration, delay: [:delay] || 0, options: [:options] || UIViewAnimationOptionCurveLinear, animations: proc{ f = self.frame f.origin = SugarCube::CoreGraphics::Point(position) self.frame = f }, completion:after ) self end |
#shake(options = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/sugarcube/uiview.rb', line 109 def shake(={}) if .is_a? Numeric duration = = {} else duration = [:duration] || 0.3 end offset = [:offset] || 8 repeat = [:repeat] || 3 duration /= repeat keypath = [:keypath] || 'transform.translation.x' origin = 0 left = -offset right = +offset animation = CAKeyframeAnimation.animationWithKeyPath(keypath) animation.duration = duration animation.repeatCount = repeat animation.values = [origin, left, right, origin] animation.keyTimes = [0, 0.25, 0.75, 1.0] self.layer.addAnimation(animation, forKey:'shake') self end |
#show ⇒ Object
7 8 9 10 |
# File 'lib/sugarcube/uiview.rb', line 7 def show self.hidden = false self end |
#slide(direction, options = {}, &after) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/sugarcube/uiview.rb', line 92 def (direction, ={}, &after) size = UIScreen.mainScreen.bounds.size case direction when :left delta_to([-size.width, 0], , &after) when :right delta_to([+size.width, 0], , &after) when :up delta_to([0, -size.height], , &after) when :down delta_to([0, +size.height], , &after) else raise "Unknown direction #{direction.inspect}" end self end |
#to_s ⇒ Object
3 4 5 6 |
# File 'lib/sugarcube/to_s/uiview.rb', line 3 def to_s "#{self.class.name}(##{self.object_id}, #{self.frame.inspect}, "\ "#{self.superview ? ' child of ' + self.superview.class.name + ' #' + self.superview.object_id.to_s : ''})" end |