Sunday, 15 September 2013

UIView inside UIScrollView gets drawn only partially

UIView inside UIScrollView gets drawn only partially

I've searched for a couple of hours without luck so I'll try asking.
I'm using a UIView subclass to represent a timeline control. The timeline
is wide and is contained within a UIScrollView. When it is drawn the first
time everything is fine, but after the view gets hidden (eg. gets behind a
modal view) the timeline view's subsequent calls to drawRect: have always
the same area. The following illustrates the issue:
// Initial call:
(lldb) p rect
(CGRect) $0 = origin=(x=0, y=0) size=(width=896, height=70)
// All the subsequent calls:
(lldb) p rect
(CGRect) $1 = origin=(x=0, y=0) size=(width=320, height=70)
Even calling setNeedsDisplay or setNeedsDisplayInRect: doesn't help. The
view contents need to be drawn only infrequently so the best alternative
would be to draw the control on some kind of persistent canvas.
Any ideas why the content is not drawn properly? My drawRect is currently
applied to the whole control without optimization and still only the
beginning of the
My simplified drawRect: looks like this:
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, self.foregroundColor.CGColor);
// ...some drawing...
// ..and multiple calls to CGContextStrokePath(context), for different
paths
// with different colors. This method ends calling
CGContextStrokePath(context).
}
I've already tried the answers found here, but no luck. Any help is
greatly appreciated.

No comments:

Post a Comment