문제

I've got a custom view called SequenceView in a NSScrollView.

It should draw 20 red rectangles in a column.

The problem : the rectangles are damaged/not drawn/drawn partially upon vertical scrolling.

Before and after the scroll: enter image description here

- (void)drawRect:(NSRect)rect {

    [[NSColor yellowColor] set];
    NSRectFill(_bounds);

    [[NSColor redColor] set];
    NSLog(@"Rect: %@",  NSStringFromRect(rect));

    float x = rect.origin.x+10;
    float y = rect.origin.y+10;
    for (unsigned i=0; i<20; i++) {
        NSRect r = NSMakeRect(x,y,30, 30);
        if (NSIntersectsRect(r, rect)){
            NSLog(@"Drawing: %@",  NSStringFromRect(r));
            [[NSBezierPath bezierPathWithRect: r] stroke];
        }
        y+=40;
    }
}
도움이 되었습니까?

해결책

See if "Copy on Scroll" for your scroll view is activated:

enter image description here

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top