DZNEmptyDataSet icon indicating copy to clipboard operation
DZNEmptyDataSet copied to clipboard

DZNEmptyDataSetView Frame Issue

Open wlisac opened this issue 10 years ago • 8 comments

DZNEmptyDataSetView sets its frame to the scroll view's bounds. I'm experiencing problems with this when reloading the DZNEmptyDataSetView while the scroll view is scrolled/scrolling.

- (void)didMoveToSuperview
{
    self.frame = self.superview.bounds;

    [UIView animateWithDuration:0.25
                     animations:^{_contentView.alpha = 1.0;}
                     completion:NULL];
}

In my specific case – the refresh control I'm using (SSPullToRefresh) adjusts the scroll view's insets and offsets while reloading and animating. This causes the DZNEmptyDataSetView to be in the "wrong" spot when I reload the DZNEmptyDataSetView during this animation.

The simplest solution for my use case is to do this:

- (void)didMoveToSuperview
{
    CGRect frame = self.superview.bounds;
    frame.origin.y = 0.0f;
    self.frame = frame;

    [UIView animateWithDuration:0.25
                     animations:^{_contentView.alpha = 1.0;}
                     completion:NULL];
}

Do you have any suggestions on how we could add this as an option to the project? We could possibly allow the delegate to provide a DZNEmptyDataSetView subclass to use. We could add an option for using a 0 y origin. (non relative origin?). Even just exposing the DZNEmptyDataSetView as a readonly property would allow a UIScrollView subclass to reposition the subview as needed.

Any thoughts on this would be appreciated.

wlisac avatar Oct 13 '15 16:10 wlisac

Another idea – we could add a delegate method that provides the initial frame for positioning in the scroll view.

wlisac avatar Oct 13 '15 16:10 wlisac

I think the last idea is the simplest solution. I've opened a pull request: https://github.com/dzenbot/DZNEmptyDataSet/pull/148

wlisac avatar Oct 13 '15 16:10 wlisac

:+1:

dzenbot avatar Oct 13 '15 18:10 dzenbot

Thank you for such a quick reply and for this library.

wlisac avatar Oct 13 '15 19:10 wlisac

- (void)didMoveToSuperview
{
    self.frame = self.superview.frame;

    [UIView animateWithDuration:0.25
                 animations:^{_contentView.alpha = 1.0;}
                 completion:NULL];
}

cooler333 avatar Oct 15 '15 16:10 cooler333

This solved the problem in my case:

- (void)emptyDataSetWillAppear:(UIScrollView *)scrollView {
    scrollView.contentOffset = CGPointZero;
}

dibelogrivaya avatar May 12 '16 18:05 dibelogrivaya

@medinaonly useful

myruntime avatar Mar 31 '17 07:03 myruntime

This solved the problem in my case:

- (void)emptyDataSetWillAppear:(UIScrollView *)scrollView {
    scrollView.contentOffset = CGPointZero;
}

It is very good. So clever. Thanks for share.

cs13886 avatar Feb 13 '19 09:02 cs13886