Class: ScreenController

Inherits:
UIViewController
  • Object
show all
Defined in:
app/controllers/screen_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#items_listObject

Returns the value of attribute items_list.



2
3
4
# File 'app/controllers/screen_controller.rb', line 2

def items_list
  @items_list
end

#tableObject

Returns the value of attribute table.



2
3
4
# File 'app/controllers/screen_controller.rb', line 2

def table
  @table
end

Instance Method Details

#after_hide_table_viewObject



67
68
69
70
# File 'app/controllers/screen_controller.rb', line 67

def after_hide_table_view
  final_point = CGPointMake(0,0)
  @animator.linear_animate(@duplicate_cell_view, to: final_point, duration: 0.3, completion: lambda{|completion| show_reverse_animator_button})
end

#after_show_table_viewObject



63
64
65
# File 'app/controllers/screen_controller.rb', line 63

def after_show_table_view
  @duplicate_cell_view.removeFromSuperview
end

#cell_was_tapped(index, duplicate_cell_view) ⇒ Object



41
42
43
44
45
46
47
# File 'app/controllers/screen_controller.rb', line 41

def cell_was_tapped index, duplicate_cell_view
  @duplicate_cell_view = duplicate_cell_view
  @original_view_position = @duplicate_cell_view.frame.origin
  self.view.addSubview(@duplicate_cell_view)
  self.view.bringSubviewToFront(@duplicate_cell_view)
  @table.hide_table_view(0.3)
end

#create_reusable_cell(index, reusable_identifier) ⇒ Object



49
50
51
52
53
54
55
# File 'app/controllers/screen_controller.rb', line 49

def create_reusable_cell index, reusable_identifier
  custom_cell = CustomCell.alloc.initWithStyle(UITableViewCellStyleDefault, reuseIdentifier: reusable_identifier)
  cell_dimensions = CGSizeMake(320, 60)
  cell_position = CGPointMake(0, 0)
  custom_cell.set_up_cell(cell_position, cell_dimensions, self.items_list[index])
  custom_cell
end

#hide_reverse_animator_buttonObject



76
77
78
# File 'app/controllers/screen_controller.rb', line 76

def hide_reverse_animator_button
  @button.alpha = 0
end

#perform_reverse_animation(sender) ⇒ Object



57
58
59
60
61
# File 'app/controllers/screen_controller.rb', line 57

def perform_reverse_animation sender
  hide_reverse_animator_button
  @animator.linear_animate(@duplicate_cell_view, to: @original_view_position, duration: 0.3, completion: nil)
  @table.show_table_view(0.3)
end

#populate_sample_dataObject



80
81
82
83
84
85
# File 'app/controllers/screen_controller.rb', line 80

def populate_sample_data
  self.items_list = []
  10.times do |n|
    self.items_list << "http://lorempixel.com/320/60/technics/#{n}"
  end
end

#prefersStatusBarHiddenObject



87
88
89
# File 'app/controllers/screen_controller.rb', line 87

def prefersStatusBarHidden
  true
end

#set_up_initial_layoutObject



11
12
13
14
15
16
17
18
# File 'app/controllers/screen_controller.rb', line 11

def set_up_initial_layout
  self.view.backgroundColor = UIColor.whiteColor
  @table = set_up_table
  @button = set_up_reverse_animator_button
  hide_reverse_animator_button
  self.view.addSubview(@table.view)
  self.view.addSubview(@button)
end

#set_up_reverse_animator_buttonObject



31
32
33
34
35
36
37
38
39
# File 'app/controllers/screen_controller.rb', line 31

def set_up_reverse_animator_button
  animator_button = UIButton.buttonWithType(UIButtonTypeCustom)
  animator_button.layer.cornerRadius = 10.0
  animator_button.addTarget(self, action: "perform_reverse_animation:", forControlEvents:UIControlEventTouchDown)
  animator_button.backgroundColor = UIColor.blackColor
  animator_button.setTitle("Reverse Animation", forState:UIControlStateNormal)
  animator_button.frame = CGRectMake(80.0, 440.0, 160.0, 40.0)
  animator_button
end

#set_up_tableObject



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/screen_controller.rb', line 20

def set_up_table
  table = AnimatedCellTableViewController.new
  table.height_of_cell = 60
  table.number_of_rows = self.items_list.count
  table.tableView.frame = self.view.bounds
  table.delegate_controller = self
  table.tableView.backgroundColor = UIColor.clearColor
  table.tableView.separatorStyle = UITableViewCellSeparatorStyleNone
  table
end

#show_reverse_animator_buttonObject



72
73
74
# File 'app/controllers/screen_controller.rb', line 72

def show_reverse_animator_button
  @button.alpha = 1
end

#viewDidLoadObject



4
5
6
7
8
9
# File 'app/controllers/screen_controller.rb', line 4

def viewDidLoad
  super
  populate_sample_data
  set_up_initial_layout
  @animator = MotionAnimator.new
end