I have create a simple, custom UIView
subclass, LineView
, which overrides drawRect:
to draw a line from the top right corner to the bottom left corner.
This LineView
is placed as subview within a UIScrollView
using fixed constraints for its height and width and top + leading constraints for its position.
When the UIScrollView
is scrolled the width constraints is updated to to change the size of the line view:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
...
self.lineViewWidthConstraint.constant = someFactorRelatedToTheCurrentScrollPosition;
[self.lineView setNeedsLayout];
}
Problem: Changing the width does NOT call the drawRect: method of the LineView
. Thus the line is not redrawn but simply squeezed or stretched. Even using setNeedsLayout
manually does not trigger the re-draw.
Any idea why the draw method is not called and how to fix this?