66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'motion-prime/sections/form/base_field_section.rb', line 66
def focus(begin_editing = false)
elements.values.detect do |element|
if element.view.is_a?(UITextField) || element.view.is_a?(UITextView)
element.view.becomeFirstResponder
end
end if begin_editing
return self unless input_view = element(:input).try(:view)
origin = input_view.frame.origin
point = container_view.convertPoint(origin, toView: form.collection_view)
nav_bar_height = screen.navigationController ? screen.navigationController.navigationBar.frame.size.height : 0
nav_bar_height += 20
offset = form.collection_view.contentOffset
new_top_offset = point.y - nav_bar_height
unless new_top_offset == offset.y
offset.y = new_top_offset
form.collection_view.setContentOffset(offset, animated: true)
end
self
rescue
NSLog("can't focus on element #{self.class_name_without_kvo}")
end
|