From fcb1553040d08b8da2a0c4fe5e06ca8e656a2004 Mon Sep 17 00:00:00 2001 From: joshaber Date: Fri, 6 Apr 2012 16:08:07 -0400 Subject: [PATCH] -[CALayer contentsScale] is 10.7+ --- lib/UIKit/TUINSView.m | 4 +++- lib/UIKit/TUIView.m | 18 +++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/UIKit/TUINSView.m b/lib/UIKit/TUINSView.m index 14bb2cc..9e307be 100644 --- a/lib/UIKit/TUINSView.m +++ b/lib/UIKit/TUINSView.m @@ -190,7 +190,9 @@ scale = [[self window] backingScaleFactor]; } - self.layer.contentsScale = scale; + if([self.layer respondsToSelector:@selector(setContentsScale:)]) { + self.layer.contentsScale = scale; + } } } diff --git a/lib/UIKit/TUIView.m b/lib/UIKit/TUIView.m index e2cb83d..e9ffc64 100644 --- a/lib/UIKit/TUIView.m +++ b/lib/UIKit/TUIView.m @@ -249,13 +249,14 @@ CGRect(^TUIViewCenteredLayout)(TUIView*) = nil; NSInteger w = b.size.width; NSInteger h = b.size.height; BOOL o = self.opaque; + CGFloat currentScale = [self.layer respondsToSelector:@selector(contentsScale)] ? self.layer.contentsScale : 1.0f; if(_context.context) { // kill if we're a different size if(w != _context.lastWidth || h != _context.lastHeight || o != _context.lastOpaque || - fabs(self.layer.contentsScale - _context.lastContentsScale) > 0.1f) + fabs(currentScale - _context.lastContentsScale) > 0.1f) { CGContextRelease(_context.context); _context.context = NULL; @@ -267,10 +268,10 @@ CGRect(^TUIViewCenteredLayout)(TUIView*) = nil; _context.lastWidth = w; _context.lastHeight = h; _context.lastOpaque = o; - _context.lastContentsScale = self.layer.contentsScale; + _context.lastContentsScale = currentScale; - b.size.width *= self.layer.contentsScale; - b.size.height *= self.layer.contentsScale; + b.size.width *= currentScale; + b.size.height *= currentScale; if(b.size.width < 1) b.size.width = 1; if(b.size.height < 1) b.size.height = 1; CGContextRef ctx = TUICreateGraphicsContextWithOptions(b.size, o); @@ -304,7 +305,8 @@ else CGContextSetRGBFillColor(context, 1, 0, 0, 0.3); CGContextFillRect(context, TUIGraphicsPushContext(context); \ if(_viewFlags.clearsContextBeforeDrawing) \ CGContextClearRect(context, b); \ - CGContextScaleCTM(context, self.layer.contentsScale, self.layer.contentsScale); \ + CGFloat scale = [self.layer respondsToSelector:@selector(contentsScale)] ? self.layer.contentsScale : 1.0f; \ + CGContextScaleCTM(context, scale, scale); \ CGContextSetAllowsAntialiasing(context, true); \ CGContextSetShouldAntialias(context, true); \ CGContextSetShouldSmoothFonts(context, !_viewFlags.disableSubpixelTextRendering); @@ -313,7 +315,7 @@ else CGContextSetRGBFillColor(context, 1, 0, 0, 0.3); CGContextFillRect(context, CA_COLOR_OVERLAY_DEBUG \ TUIImage *image = TUIGraphicsGetImageFromCurrentImageContext(); \ layer.contents = (id)image.CGImage; \ - CGContextScaleCTM(context, 1.0f / self.layer.contentsScale, 1.0f / self.layer.contentsScale); \ + CGContextScaleCTM(context, 1.0f / scale, 1.0f / scale); \ TUIGraphicsPopContext(); \ if(self.drawInBackground) [CATransaction flush]; @@ -808,7 +810,9 @@ else CGContextSetRGBFillColor(context, 1, 0, 0, 0.3); CGContextFillRect(context, scale = [[self nsWindow] backingScaleFactor]; } - self.layer.contentsScale = scale; + if([self.layer respondsToSelector:@selector(setContentsScale:)]) { + self.layer.contentsScale = scale; + } } for(TUIView *subview in self.subviews) {