Domanda

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;
    }
}
È stato utile?

Soluzione

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

enter image description here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top