| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- //
- // UIScrollView+Empty.m
- // UIScrollViewEmpty
- //
- // Created by Jack on 2018/9/5.
- // Copyright © 2018年 United Software Applications. All rights reserved.
- //
- #import "UIScrollView+Empty.h"
- #import "RAEmptyDataView.h"
- #import <objc/runtime.h>
- static const char *emptyKey = "emptyKey";
- static const float duration = 0.25;
- @implementation UIScrollView (Empty)
- - (void)setEmptyContentView:(RAEmptyDataView *)contentView {
- if (contentView) {
- UIView *view = objc_getAssociatedObject(self, emptyKey);
- if (view) {
- [view removeFromSuperview];
- }
-
- [self insertSubview:contentView atIndex:0];
-
- [self willChangeValueForKey:@"emptyView"];
- objc_setAssociatedObject(self, emptyKey, contentView, OBJC_ASSOCIATION_RETAIN);
- [self didChangeValueForKey:@"emptyView"];
- }
- }
- - (RAEmptyDataView *)emptyContentView {
-
- RAEmptyDataView *contentView = objc_getAssociatedObject(self, emptyKey);
-
- if (!contentView) {
- contentView = [RAEmptyDataView new];
- contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
- contentView.hidden = YES;
-
- [self setEmptyContentView:contentView];
- }
-
- return contentView;
- }
- - (void)setEmptyView:(UIView *)emptyView {
- [self emptyContentView].emptyView = emptyView;
- }
- - (UIView *)emptyView {
- return [self emptyContentView].emptyView;
- }
- - (void)showEmpty {
- UIView *view = [self emptyContentView];
- // view.alpha = 0.0f;
- view.hidden = NO;
-
- // [UIView animateWithDuration:duration animations:^{
- // view.alpha = 1.0f;
- // }];
- }
- - (void)hideEmpty {
- UIView *view = [self emptyContentView];
- // [UIView animateWithDuration:duration animations:^{
- // view.alpha = 0.0f;
- // } completion:^(BOOL finished) {
- view.hidden = YES;
- // }];
- }
- @end
|