Skip to content

Commit

Permalink
layoutIfNeeded fixes, and scroll_view support (assign the parent scro…
Browse files Browse the repository at this point in the history
…ll view and stand back in amazement)
  • Loading branch information
colinta committed Jul 31, 2012
1 parent b20b414 commit 41721e6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/typewriter/view.rb
Expand Up @@ -2,6 +2,7 @@
# left-to-right until the frame width is reached, and then drops down to the
# next row.
class TypewriterView < UIView
attr_accessor :scroll_view

attr_accessor :vertical_spacing, :horizontal_spacing
attr_accessor :top_margin, :bottom_margin
Expand Down Expand Up @@ -109,6 +110,10 @@ def right_margin
##| START AT 0, 0, AND START FLOATING
##|
def layoutSubviews
layoutIfNeeded
end
def layoutIfNeeded
super
# the max_height of *all* the rows so far (not just the current row)
@max_height = top_margin
clear
Expand All @@ -117,10 +122,15 @@ def layoutSubviews
@max_x = self.frame.size.width - right_margin

self.subviews.each do |view|
view.layoutSubviews
add_next(view)
end
clear

self.frame = [self.frame.origin, [self.frame.size.width, @y]]
if scroll_view
scroll_view.scrollEnabled = (@y > scroll_view.frame.size.height)
scroll_view.contentSize = self.frame.size
end
end

private
Expand Down

0 comments on commit 41721e6

Please sign in to comment.