Thanks Gideon. 

Turning on the layer backing for all those levels did fix the redrawing problem.

I didn't find out how to fix the layer drawing when the bounds origin has been 
moved, but I did work out a workaround.

I added an instance variable to my view (the scrollview's document view):
@property (assign) NSPoint originOffset;

I set that to the offset from the origin to where I want the bounds origin to 
be, then in drawRect, I do:
    CGContextRef currentContext = NSGraphicsContext.currentContext.graphicsPort;
    CGContextSaveGState(currentContext);
    CGContextTranslateCTM(currentContext, self.originOffset.x, 
self.originOffset.y);
...do all my drawing relative to where the bounds origin should be
    CGContextRestoreGState(currentContext);

That gets my view drawing properly, but I still have the problem of positioning 
my subviews, so I created a view that I will never draw as follows:

@implementation OffsetView
- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
        self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawNever;
    }
    return self;
}
- (BOOL)isFlipped {
    return YES;
}
@end

Then in my main view, I add the following:
    OffsetView *offsetView = [[OffsetView alloc] initWithFrame:self.bounds];
    [offsetView setBoundsOrigin:NSMakePoint(-self.originOffset.x, 
-self.originOffset.y)];
    [self addSubview:offsetView];

And now I just add my subviews to the offset view instead of the main view.

This does seem like a nasty hack to get the result I want, but it works, and 
nobody else has suggested any alternative, so I'll just run with it.

Thanks again for the help.

Ken

On Oct 18, 2013, at 03:20 PM, Gideon King <gid...@novamind.com> wrote:

I knew I was going to want to do something like that myself so created a small 
test project.
...
Can anyone else help with how to draw a layer backed view where the bounds 
origin has been shifted?


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to