From 7b9c2734aa5832606099fb1dee7b3ed188d627d4 Mon Sep 17 00:00:00 2001 From: benrudhart Date: Mon, 11 Jan 2016 14:15:56 +0100 Subject: [PATCH] fix false origin y of emptyDataSetView when scrollview had been scrolled --- Source/UIScrollView+EmptyDataSet.m | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Source/UIScrollView+EmptyDataSet.m b/Source/UIScrollView+EmptyDataSet.m index 9c833b0d..f859237b 100644 --- a/Source/UIScrollView+EmptyDataSet.m +++ b/Source/UIScrollView+EmptyDataSet.m @@ -422,13 +422,15 @@ - (void)dzn_reloadEmptyDataSet DZNEmptyDataSetView *view = self.emptyDataSetView; if (!view.superview) { + [self addSubview:view]; + // 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]; - } - else { - [self addSubview:view]; - } + [self sendSubviewToBack:view]; + + // make sure the y origin of view is 0. adding it to a scrollView may have changed it + CGRect frame = view.frame; + frame.origin.y = 0; + view.frame = frame; } // Removing view resetting the view and its constraints it very important to guarantee a good state