From 83cad0c86713cbf0b9a5b7d60beadc42fc9605d6 Mon Sep 17 00:00:00 2001 From: Andrew Podkovyrin Date: Thu, 24 Apr 2014 00:40:57 +0400 Subject: [PATCH] generate blur frames only once on addSubview: --- ANBlurredImageView/ANBlurredImageView.m | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/ANBlurredImageView/ANBlurredImageView.m b/ANBlurredImageView/ANBlurredImageView.m index 0d19b39..c0b4cf7 100644 --- a/ANBlurredImageView/ANBlurredImageView.m +++ b/ANBlurredImageView/ANBlurredImageView.m @@ -19,15 +19,17 @@ - (id)initWithFrame:(CGRect)frame return self; } --(void)layoutSubviews{ - [super layoutSubviews]; +- (void)willMoveToSuperview:(UIView *)newSuperview { + [super willMoveToSuperview:newSuperview]; - _baseImage = self.image; - [self generateBlurFramesWithCompletion:^{}]; - - // Defaults - self.animationDuration = 0.1f; - self.animationRepeatCount = 1; + if (newSuperview) { + _baseImage = self.image; + [self generateBlurFramesWithCompletion:^{}]; + + // Defaults + self.animationDuration = 0.1f; + self.animationRepeatCount = 1; + } } // Downsamples the image so we avoid needing to blur a huge image.