From bfe21f589149a7eb2a0b5615b0263b7e130f5d2e Mon Sep 17 00:00:00 2001 From: Wenchao Ding Date: Sat, 14 May 2016 13:50:06 +0800 Subject: [PATCH] Fix fade-in effect Fix fade-in effect --- Source/UIScrollView+EmptyDataSet.m | 31 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Source/UIScrollView+EmptyDataSet.m b/Source/UIScrollView+EmptyDataSet.m index dc9b9fd7..dcde353f 100644 --- a/Source/UIScrollView+EmptyDataSet.m +++ b/Source/UIScrollView+EmptyDataSet.m @@ -448,6 +448,9 @@ - (void)dzn_reloadEmptyDataSet DZNEmptyDataSetView *view = self.emptyDataSetView; + // Configure empty dataset fade in display + view.fadeInOnDisplay = [self dzn_shouldFadeIn]; + if (!view.superview) { // Send the view all the way to the back, in case a header and/or footer is present, as well as for sectionHeaders or any other content if (([self isKindOfClass:[UITableView class]] || [self isKindOfClass:[UICollectionView class]]) && self.subviews.count > 1) { @@ -527,9 +530,6 @@ - (void)dzn_reloadEmptyDataSet // Configure empty dataset userInteraction permission view.userInteractionEnabled = [self dzn_isTouchAllowed]; - // Configure empty dataset fade in display - view.fadeInOnDisplay = [self dzn_shouldFadeIn]; - [view setupConstraints]; [UIView performWithoutAnimation:^{ @@ -740,17 +740,19 @@ - (instancetype)init - (void)didMoveToSuperview { - self.frame = self.superview.bounds; - - void(^fadeInBlock)(void) = ^{_contentView.alpha = 1.0;}; - - if (self.fadeInOnDisplay) { - [UIView animateWithDuration:0.25 - animations:fadeInBlock - completion:NULL]; - } - else { - fadeInBlock(); + [super didMoveToSuperview]; + if (self.superview) { + + self.frame = self.superview.bounds; + + if (self.fadeInOnDisplay) { + CABasicAnimation *alpha = [CABasicAnimation animationWithKeyPath:@"opacity"]; + alpha.fromValue = @0; + alpha.toValue = @1; + alpha.duration = 0.25; + [_contentView.layer addAnimation:alpha forKey:@"alpha"]; + } + } } @@ -765,7 +767,6 @@ - (UIView *)contentView _contentView.translatesAutoresizingMaskIntoConstraints = NO; _contentView.backgroundColor = [UIColor clearColor]; _contentView.userInteractionEnabled = YES; - _contentView.alpha = 0; } return _contentView; }