MaddTheSane / SVGKit

A Cocoa framework for rendering SVG files as Core Animation layers
http://mattrajca.com
Other
48 stars 18 forks source link

CALayer coordinate system flipped #16

Open azplanlos opened 9 years ago

azplanlos commented 9 years ago

When adding a CALayer for a single SVGElement the CALayer is rendered flipped. I'm doing this in a NSView subclass:

SVGElement* elem = …;
CALayer* layer = [svgImage layerWithIdentifier:elem.identifier];
[self.layer addSublayer:layer];
MaddTheSane commented 9 years ago

The quick-and-dirty solution would probably have your NSView subclass be flipped:

- (BOOL)isFlipped {
    return YES;
}

I realize this might not be ideal if you want to do your own drawing on your own class, though.

azplanlos commented 9 years ago

Thanks for your quick reply. I ended up using CALayer’s “geometryFlipped” property in combination with a custom category flipping coordinates on CALayer’s frame property in order to compose an image from multiple groups stored in a SVG file.

@implementation CALayer (flipPos)

-(void)flipCoordinatesForRect:(NSRect)frameRect { self.frame = NSMakeRect(self.frame.origin.x, frameRect.size.height - (self.frame.origin.y + self.frame.size.height), self.frame.size.width, self.frame.size.height); }

@end

Andreas Zöllner Sent with Airmail

Absender: MaddTheSane notifications@github.commailto:notifications@github.com Antworten: MaddTheSane/SVGKit reply@reply.github.commailto:reply@reply.github.com Datum: 17. Januar 2015 at 22:15:58 Empfänger: MaddTheSane/SVGKit svgkit@noreply.github.commailto:svgkit@noreply.github.com CC: Andreas Zöllner andi@go-for-fun.demailto:andi@go-for-fun.de Betreff: Re: [SVGKit] CALayer coordinate system flipped (#16)

The quick-and-dirty solution would probably have your NSView subclass be flipped:

I realize this might not be ideal if you want to do your own drawing on your own class, though.

— Reply to this email directly or view it on GitHubhttps://github.com/MaddTheSane/SVGKit/issues/16#issuecomment-70382522.