diff --git a/Source/UIScrollView+EmptyDataSet.h b/Source/UIScrollView+EmptyDataSet.h index 43655355..2c6c18f8 100644 --- a/Source/UIScrollView+EmptyDataSet.h +++ b/Source/UIScrollView+EmptyDataSet.h @@ -84,7 +84,7 @@ * * @return image animation */ -- (CAAnimation *) imageAnimationForEmptyDataSet:(UIScrollView *) scrollView; +- (CAAnimation *)imageAnimationForEmptyDataSet:(UIScrollView *) scrollView; /** Asks the data source for the title to be used for the specified button state. @@ -143,6 +143,14 @@ - (CGPoint)offsetForEmptyDataSet:(UIScrollView *)scrollView DEPRECATED_MSG_ATTRIBUTE("Use -verticalOffsetForEmptyDataSet:"); - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView; +/** + Asks the data source for an initial frame for the empty data set view. Default is the scroll view's bounds. + + @param scrollView A scrollView subclass object informing the delegate. + @return The initial frame for the empty data set view. + */ +- (CGRect)initialFrameForEmptyDataSet:(UIScrollView *)scrollView; + /** Asks the data source for a vertical space between elements. Default is 11 pts. diff --git a/Source/UIScrollView+EmptyDataSet.m b/Source/UIScrollView+EmptyDataSet.m index a96790fb..cad8a0de 100644 --- a/Source/UIScrollView+EmptyDataSet.m +++ b/Source/UIScrollView+EmptyDataSet.m @@ -254,6 +254,16 @@ - (CGFloat)dzn_verticalOffset return offset; } +- (CGRect)dzn_initialFrame +{ + CGRect frame = self.bounds; + + if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(initialFrameForEmptyDataSet:)]) { + frame = [self.emptyDataSetSource initialFrameForEmptyDataSet:self]; + } + return frame; +} + - (CGFloat)dzn_verticalSpace { if (self.emptyDataSetSource && [self.emptyDataSetSource respondsToSelector:@selector(spaceHeightForEmptyDataSet:)]) { @@ -413,6 +423,8 @@ - (void)dzn_reloadEmptyDataSet DZNEmptyDataSetView *view = self.emptyDataSetView; if (!view.superview) { + view.frame = [self dzn_initialFrame]; + // 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) { [self insertSubview:view atIndex:0]; @@ -681,8 +693,6 @@ - (instancetype)init - (void)didMoveToSuperview { - self.frame = self.superview.bounds; - [UIView animateWithDuration:0.25 animations:^{_contentView.alpha = 1.0;} completion:NULL];