From 05b4110edd20412a2fcf45c61a33c05fa8877209 Mon Sep 17 00:00:00 2001 From: liww Date: Tue, 19 Dec 2017 19:48:34 +0800 Subject: [PATCH] Update DLTiledImageView.m --- .../View/TiledImageView/DLTiledImageView.m | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/DLPhotoPicker/View/TiledImageView/DLTiledImageView.m b/DLPhotoPicker/View/TiledImageView/DLTiledImageView.m index c6f3e1c..1e4f9b6 100644 --- a/DLPhotoPicker/View/TiledImageView/DLTiledImageView.m +++ b/DLPhotoPicker/View/TiledImageView/DLTiledImageView.m @@ -47,19 +47,24 @@ - (void)setImage:(UIImage *)image { - (void)drawRect:(CGRect)rect { if (self.image) { - dispatch_async(dispatch_get_main_queue(), ^{ - CGContextRef ctx = UIGraphicsGetCurrentContext(); - CGContextSaveGState(ctx); + __block CGRect rect = CGRectZero; + if (![NSThread isMainThread]) { + dispatch_sync(dispatch_get_main_queue(), ^{ + rect = self.bounds; + }); + }else { + rect = self.bounds; + } - CGRect rect = self.bounds; - - CGContextTranslateCTM(ctx, rect.origin.x, rect.origin.y); - CGContextTranslateCTM(ctx, 0.0, rect.size.height); - CGContextScaleCTM(ctx, 1.0, -1.0); - CGContextTranslateCTM(ctx, -rect.origin.x, -rect.origin.y); - CGContextDrawImage(ctx, rect, self.image.CGImage); - CGContextRestoreGState(ctx); - }); + // + CGContextRef ctx = UIGraphicsGetCurrentContext(); + CGContextSaveGState(ctx); + CGContextTranslateCTM(ctx, rect.origin.x, rect.origin.y); + CGContextTranslateCTM(ctx, 0.0, rect.size.height); + CGContextScaleCTM(ctx, 1.0, -1.0); + CGContextTranslateCTM(ctx, -rect.origin.x, -rect.origin.y); + CGContextDrawImage(ctx, rect, self.image.CGImage); + CGContextRestoreGState(ctx); } }