1

In My Application I've subclassed the UIScrollView and draw horizontal Lines in the drawRect method

I set the height the ContentSize greater than the height of scrollView. I use below method to draw the lines

But my problem is that the lines I have drawn is not scrolling with View.

-(id)initWithFFrame:(CGRect)rect
{
  _gap=36;
}
- (void)drawRect:(CGRect)rect
{
    // Drawing code
    int end=0;
    NSLog(@"called");
    int x=self.frame.size.width;
    while (end<self.contentSize.height) {
        CGContextRef context=UIGraphicsGetCurrentContext();
        CGContextSetLineWidth(context, 1);
        CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
        CGContextMoveToPoint(context, 0, end);
        CGContextAddLineToPoint(context, x, end);
        CGContextStrokePath(context);
        end=end+_gap;
    }
}

I can notice the scroller moving up and down when scrolling but the lines are not moving.

4

1 回答 1

2

The problem is that those lines are part of the UIScrollView and not of it's content.

You need to create a new UIView subclass, draw the content there, and add this to your UIScrollView

于 2013-04-29T13:25:37.093 回答