Class: AnimatedCellTableViewController

Inherits:
UITableViewController
  • Object
show all
Defined in:
lib/motion-animated-cell-table/animated_cell_table_view_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#delegate_controllerObject

Returns the value of attribute delegate_controller.



2
3
4
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 2

def delegate_controller
  @delegate_controller
end

#height_of_cellObject

Returns the value of attribute height_of_cell.



2
3
4
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 2

def height_of_cell
  @height_of_cell
end

#number_of_rowsObject

Returns the value of attribute number_of_rows.



2
3
4
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 2

def number_of_rows
  @number_of_rows
end

Instance Method Details

#create_duplicate_view_from_cell(table_view, index_path) ⇒ Object



10
11
12
13
14
15
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 10

def create_duplicate_view_from_cell(table_view, index_path)
  cell = tableView(table_view, cellForRowAtIndexPath: index_path)
  view_position = get_cell_position_on_screen(table_view, index_path)
  view_dimensions = get_cell_dimensions(cell)
  cell.set_up_duplicate_cell_view(view_position, view_dimensions)
end

#get_cell_dimensions(cell) ⇒ Object



72
73
74
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 72

def get_cell_dimensions(cell)
  cell.get_frame_size
end

#get_cell_position_on_screen(table_view, index_path) ⇒ Object



68
69
70
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 68

def get_cell_position_on_screen(table_view, index_path)
  CGPointMake(table_view.contentOffset.x, self.height_of_cell * index_path.row - table_view.contentOffset.y)
end

#hide_cell?(index) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 32

def hide_cell?(index)
  @hidden_cell_index == index
end

#hide_table_view(duration) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 56

def hide_table_view(duration)
  UIView.animateWithDuration(duration,
                             animations: lambda{
                               self.tableView.alpha = 0
                             },
                             completion: lambda{|completion|
                               self.tableView.hidden = true
                               self.delegate_controller.after_hide_table_view
                             }
                             )
end

#numberOfSectionsInTableView(table_view) ⇒ Object



81
82
83
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 81

def numberOfSectionsInTableView(table_view)
  1
end

#show_hidden_cellObject



27
28
29
30
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 27

def show_hidden_cell
  index_path = NSIndexPath.indexPathForRow(@hidden_cell_index, inSection: 0)
  toggle_cell_visibility(self.tableView, index_path)
end

#show_table_view(duration) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 43

def show_table_view(duration)
  self.tableView.hidden = false
  UIView.animateWithDuration(duration,
                             animations: lambda{
                               self.tableView.alpha = 1
                             },
                             completion: lambda{|completion|
                               show_hidden_cell
                               self.delegate_controller.after_show_table_view
                             }
                             )
end

#tableView(tableView, heightForRowAtIndexPath: indexPath) ⇒ Object



4
5
6
7
8
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 4

def tableView(table_view, didSelectRowAtIndexPath: index_path)
  duplicate_cell_view = create_duplicate_view_from_cell(table_view, index_path)
  toggle_cell_visibility(table_view, index_path)
  self.delegate_controller.cell_was_tapped(index_path.row, duplicate_cell_view)
end

#toggle_cell_visibility(table_view, index_path) ⇒ Object



36
37
38
39
40
41
# File 'lib/motion-animated-cell-table/animated_cell_table_view_controller.rb', line 36

def toggle_cell_visibility(table_view, index_path)
  cell = tableView(table_view, cellForRowAtIndexPath: index_path)
  cell.hidden = !cell.isHidden
  @hidden_cell_index = cell.isHidden ? index_path.row : nil
  self.tableView.reloadData
end