Skip to content
This repository was archived by the owner on Nov 29, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions Source/UIScrollView+EmptyDataSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ - (void)dzn_reloadEmptyDataSet

DZNEmptyDataSetView *view = self.emptyDataSetView;

// Configure empty dataset fade in display
view.fadeInOnDisplay = [self dzn_shouldFadeIn];
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was moved up a little because in some cases, the method didMoveToSuperview was called before the value fadeInOnDisplay was set up. So I thought it would be better to set it before addSubview.


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) {
Expand Down Expand Up @@ -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:^{
Expand Down Expand Up @@ -735,17 +735,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) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that when the view is removed from superview, this method will get called too. For that case, self.superview would be nil.


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"];
}

}
}

Expand All @@ -760,7 +762,6 @@ - (UIView *)contentView
_contentView.translatesAutoresizingMaskIntoConstraints = NO;
_contentView.backgroundColor = [UIColor clearColor];
_contentView.userInteractionEnabled = YES;
_contentView.alpha = 0;
}
return _contentView;
}
Expand Down