Sha256: 1582af9d88e7b20f877b90e134ce0ba10180a4a004e73c1a6156f9ac4820e58c
Contents?: true
Size: 1.19 KB
Versions: 18
Compression:
Stored size: 1.19 KB
Contents
module MotionKit module_function # performs a breadth-first search def find_first_view(root, &condition) if condition.call(root) root else found = nil root.subviews.find do |subview| found = find_first_view(subview, &condition) end return found end end # performs a depth-first and reversed search def find_last_view(root, &condition) found = nil root.subviews.reverse.find do |subview| found = find_last_view(subview, &condition) end if ! found && condition.call(root) found = root end return found end # performs a breadth-first search, but returns all matches def find_all_views(root, &condition) found = [] if condition.call(root) found << root end (root.subviews || []).each do |subview| found.concat(find_all_views(subview, &condition)) end return found end # similar to find_all_views, but for CALayer def find_all_layers(root, &condition) found = [] if condition.call(root) found << root end (root.sublayers || []).each do |sublayer| found.concat(find_all_layers(sublayer, &condition)) end return found end end
Version data entries
18 entries across 18 versions & 1 rubygems