Class: Motion::Xray::XrayLockButton

Inherits:
UIButton
  • Object
show all
Defined in:
lib/motion-xray/views/xray_lock_button.rb

Constant Summary collapse

States =
4
LockedState =
0
UnlockedState =
1
LockedVerticalState =
2
LockedHorizontalState =
3
InitialState =
LockedState
UnlockedImage =
'xray_lock_button_unlocked'.uiimage
LockedHorizontalImage =
'xray_lock_button_horizontal'.uiimage
LockedVerticalImage =
'xray_lock_button_vertical'.uiimage
LockedImage =
'xray_lock_button_locked'.uiimage

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from UIButton

#xray_subviews

Instance Attribute Details

#lock_stateObject (readonly)

Returns the value of attribute lock_state


16
17
18
# File 'lib/motion-xray/views/xray_lock_button.rb', line 16

def lock_state
  @lock_state
end

Instance Method Details

#initObject


18
19
20
21
# File 'lib/motion-xray/views/xray_lock_button.rb', line 18

def init
  frame = [[0, 0], UnlockedImage.size]
  initWithFrame(frame)
end

#initWithFrame(frame) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/motion-xray/views/xray_lock_button.rb', line 23

def initWithFrame(frame)
  super.tap do
    @lock_state = InitialState
    update_state
    self.on :touch do
      @lock_state += 1
      @lock_state = @lock_state % States
      update_state
    end
  end
end

#update_stateObject


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/motion-xray/views/xray_lock_button.rb', line 35

def update_state
  case @lock_state
  when UnlockedState
    self.setImage(UnlockedImage, forState: :normal.uicontrolstate)
  when LockedVerticalState
    self.setImage(LockedVerticalImage, forState: :normal.uicontrolstate)
  when LockedHorizontalState
    self.setImage(LockedHorizontalImage, forState: :normal.uicontrolstate)
  when LockedState
    self.setImage(LockedImage, forState: :normal.uicontrolstate)
  end
end