Commit 0ec6593c authored by 汪洋's avatar 汪洋

删除emptyView,移到GMKit中

parent 56fd8522
......@@ -14,8 +14,10 @@ PODS:
- AFNetworking/Serialization (3.1.0)
- AFNetworking/UIKit (3.1.0):
- AFNetworking/NSURLSession
- Base64nl (1.2)
- GMBase (0.0.24):
- GMHud (= 0.1.1)
- GMHud
- GMKit
- GMNetService
- GMPhobos
- GMRefresh
......@@ -25,10 +27,44 @@ PODS:
- UITableView+FDTemplateLayoutCell (= 1.4)
- GMCache (0.1.1):
- TMCache (~> 2.1.0)
- GMFoundation (0.0.4):
- Base64nl (= 1.2)
- GMHud (0.1.1):
- MBProgressHUD (= 0.9.2)
- GMKit (0.7.19):
- GMFoundation
- GMKit/Category (= 0.7.19)
- GMKit/FDFullscreenPopGesture (= 0.7.19)
- GMKit/Kit (= 0.7.19)
- GMKit/Protocol (= 0.7.19)
- GMOCConstant
- Masonry (= 1.0.1)
- SDWebImage (= 3.7.6)
- GMKit/Category (0.7.19):
- GMFoundation
- GMOCConstant
- Masonry (= 1.0.1)
- SDWebImage (= 3.7.6)
- GMKit/FDFullscreenPopGesture (0.7.19):
- GMFoundation
- GMOCConstant
- Masonry (= 1.0.1)
- SDWebImage (= 3.7.6)
- GMKit/Kit (0.7.19):
- GMFoundation
- GMKit/Category (= 0.7.19)
- GMKit/Protocol (= 0.7.19)
- GMOCConstant
- Masonry (= 1.0.1)
- SDWebImage (= 3.7.6)
- GMKit/Protocol (0.7.19):
- GMFoundation
- GMOCConstant
- Masonry (= 1.0.1)
- SDWebImage (= 3.7.6)
- GMNetService (0.1.5):
- AFNetworking (= 3.1.0)
- GMOCConstant (0.0.3)
- GMPhobos (0.3.3):
- GMCache (~> 0.1.1)
- GMRefresh (0.1.5):
......@@ -37,6 +73,9 @@ PODS:
- Masonry (1.0.1)
- MBProgressHUD (0.9.2)
- MJRefresh (3.1.12)
- SDWebImage (3.7.6):
- SDWebImage/Core (= 3.7.6)
- SDWebImage/Core (3.7.6)
- TMCache (2.1.0)
- UITableView+FDTemplateLayoutCell (1.4)
......@@ -49,16 +88,21 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67
GMBase: e102d39978d80f37f6aa546f362877ce6031f1b9
Base64nl: a497bdcd1c01ea793d36b399016195a8713c0e95
GMBase: fbf9da56b66675368d536b402f06502386e582d7
GMCache: 73855b613b9d7e34f4f37ad425e8b8153b760c04
GMFoundation: 395f1083c40aa38e9fb031726991dbc20247e2f9
GMHud: 67c24abb83777c61e43741d4a803f7b6d8ad4e1e
GMKit: c23a05b5505b5f72b6c34686fa9a56a5ab6efc6f
GMNetService: 59825077fcb1b7d332023e9ad511239dc70a8879
GMOCConstant: 39371248b4d8d54929391bfcd2c5883776436c4b
GMPhobos: c32984b4902cb6dd931a53d647931c2d4fc00a12
GMRefresh: b9f0674b9b14c533ec2586147ea40a833ed5867d
JSONModel: 12523685c4b623553ccf844bbbf7007624317b2c
Masonry: a1a931a0d08870ed8ae415a2ea5ea68ebcac77df
MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1
MJRefresh: b96cdb21c4aa75a7b07654311ab2f315c497e806
SDWebImage: c325cf02c30337336b95beff20a13df489ec0ec9
TMCache: 95ebcc9b3c7e90fb5fd8fc3036cba3aa781c9bed
UITableView+FDTemplateLayoutCell: 234e1582bcc4e18461af91155123bb96538ed030
......
......@@ -17,5 +17,6 @@ Pod::Spec.new do |s|
s.dependency 'MBProgressHUD'
s.dependency 'Masonry' , '1.0.1'
s.dependency 'GMPhobos'
s.dependency 'GMHud', '0.1.1'
s.dependency 'GMHud'
s.dependency 'GMKit'
end
//
// OCEmptyView.h
// Gengmei
//
// Created by wangyang on 16/7/9.
// Copyright © 2016年 更美互动信息科技有限公司. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface OCRedGradientButton : UIButton
@end
typedef NS_ENUM(NSUInteger, OCEmptyViewType) {
OCEmptyViewTypeEmpty,
OCEmptyViewTypeException
};
@protocol OCEmptyViewDelegate <NSObject>
- (void)emptyViewDidClickReload;
@end
@interface OCEmptyView : UIView
@property (nonatomic, strong) UIImageView *tipIcon;
@property (nonatomic, strong) UILabel *tipLabel;
@property (nonatomic, strong) OCRedGradientButton *tipButton;
@property (nonatomic, assign) OCEmptyViewType type;
@property (nonatomic, weak) id<OCEmptyViewDelegate> delegate;
@property (nonatomic, copy) NSString *tipImage;
@property (nonatomic, copy) NSString *tipText;
@end
//
// OCEmptyView.m
// Gengmei
//
// Created by wangyang on 16/7/9.
// Copyright © 2016年 更美互动信息科技有限公司. All rights reserved.
//
#import "OCEmptyView.h"
#import "GMBaseUtil.h"
#import <Masonry/Masonry.h>
@implementation OCRedGradientButton
-(id)init
{
self = [super init];
if (self) {
self.clipsToBounds = YES;
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.clipsToBounds = YES;
}
return self;
}
- (void)layoutSubviews{
[super layoutSubviews];
self.layer.cornerRadius = MIN(self.frame.size.height, self.frame.size.width)/2;
}
- (void)drawRect:(CGRect)rect{
NSArray *colors = @[[UIColor colorWithRed:1 green:89.0/255 blue:99.0/255 alpha:1],[UIColor colorWithRed:1 green:112.0/255 blue:150.0/255 alpha:1]];
NSMutableArray *ar = [NSMutableArray array];
for(UIColor *c in colors) {
[ar addObject:(id)c.CGColor];
}
UIGraphicsBeginImageContextWithOptions(self.frame.size, YES, 1);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGColorSpaceRef colorSpace = CGColorGetColorSpace([[colors lastObject] CGColor]);
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)ar, NULL);
CGPoint start = CGPointMake(self.frame.size.width, 0.0);
CGPoint end = CGPointMake(0, self.frame.size.height);
CGContextDrawLinearGradient(context, gradient, start, end, kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
CGGradientRelease(gradient);
CGContextRestoreGState(context);
CGColorSpaceRelease(colorSpace);
UIGraphicsEndImageContext();
[self setBackgroundImage:image forState:UIControlStateNormal];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}
@end
@implementation OCEmptyView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (void)awakeFromNib{
[super awakeFromNib];
[self setup];
}
- (void)setup{
self.backgroundColor = [UIColor whiteColor];
_tipIcon = [UIImageView new];
_tipLabel = [UILabel new];
_tipButton = [OCRedGradientButton buttonWithType:UIButtonTypeCustom];
_tipButton.frame = CGRectMake(0, 0, 10, 10); //给一个默认的rect,让系统调用DrawRect方法
[self addSubview:_tipIcon];
[_tipIcon addSubview:_tipLabel];
[self addSubview:_tipButton];
_tipLabel.numberOfLines = 2;
_tipLabel.preferredMaxLayoutWidth = 300;
_tipLabel.textColor = [UIColor colorWithhex:0x666666];
_tipLabel.font = [UIFont navigationFontWithSize:15];
_tipLabel.textAlignment = NSTextAlignmentCenter;
_tipButton.hidden = YES;
[_tipButton setTitle:@"重新加载" forState:UIControlStateNormal];
_tipButton.titleLabel.font = [UIFont navigationFontWithSize:16];
[_tipButton setTitleColor:[UIColor colorWithhex:0x666666] forState:UIControlStateNormal];
[_tipButton addTarget:self action:@selector(reloadBtnTap) forControlEvents:UIControlEventTouchUpInside];
}
- (void)setType:(OCEmptyViewType)type{
_type = type;
switch (self.type) {
case OCEmptyViewTypeEmpty:{
_tipButton.hidden = YES;
_tipIcon.image = [UIImage imageNamed:@"empty"];
_tipLabel.text = @"此处太寂寥,社区等你撩";
break;
}
case OCEmptyViewTypeException:{
_tipButton.hidden = NO;
_tipIcon.image = [UIImage imageNamed:@"network_failed"];
_tipLabel.text = @"原谅我一看到美人就不淡定";
}
default:
break;
}
}
- (void)layoutSubviews {
[super layoutSubviews];
if (_tipImage.length > 0) {
_tipIcon.image = [UIImage imageNamed:_tipImage];
}
if (_tipText.length > 0) {
_tipLabel.text = _tipText;
}
}
- (void)updateConstraints{
[super updateConstraints];
[_tipIcon mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.centerY.equalTo(self).offset(-75);
// make.size.mas_equalTo(CGSizeMake(175, 198));
}];
[_tipLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(_tipIcon.mas_bottom).offset(-15);
make.centerX.mas_equalTo(self);
}];
[_tipButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_tipIcon.mas_bottom).offset(15);
make.centerX.equalTo(self);
make.width.mas_equalTo(150);
make.height.mas_equalTo(33);
}];
}
- (void)reloadBtnTap {
if ([self.delegate respondsToSelector:@selector(emptyViewDidClickReload)]) {
[self.delegate emptyViewDidClickReload];
}
}
@end
......@@ -35,6 +35,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, readonly) OCNavigatioinBarButton *rightButton;
@property (nonatomic, strong, readonly) OCNavigatioinBarButton *nearRightButton;
/**
leftIcon 有默认值:back
*/
@property (nonatomic, copy, nullable) NSString *leftIcon;
@property (nonatomic, copy, nullable) NSString *rightIcon;
@property (nonatomic, copy, nullable) NSString *nearRightIcon;
......
......@@ -8,7 +8,6 @@
#import "WMBaseViewController.h"
#import "WMFetchDataViewModel.h"
#import "OCEmptyView.h"
@interface WMBaseCollectionController : WMBaseViewController <UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>{
BOOL _needHeaderRefresh;
......@@ -26,8 +25,6 @@
*/
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) OCEmptyView *emptyView;
/**
* @brief 默认返回一个 flowLayout
@code
......
......@@ -12,7 +12,7 @@
#import <Masonry/Masonry.h>
@import GMHud;
@interface WMBaseCollectionController () <OCEmptyViewDelegate>
@interface WMBaseCollectionController ()
@end
......@@ -41,22 +41,6 @@
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(64, 0, 0, 0));
}];
// collectionView的EmptyView
_emptyView = [[OCEmptyView alloc] initWithFrame:CGRectZero];
_emptyView.hidden = YES;
if([self getEmptyText].length > 0){
_emptyView.tipText = [self getEmptyText];
}
_emptyView.delegate = self;
[self.view addSubview:_emptyView];
[_emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.top.mas_equalTo(0);
make.bottom.mas_equalTo(0);
}];
__weak __typeof(self)weakSelf = self;
if (_needHeaderRefresh) {
_collectionView.mj_header = [GMRefreshHeader headerWithRefreshingBlock:^{
......@@ -69,7 +53,6 @@
}];
}
//获取数据
if (_immediateLoad) {
[self loadRemoteData];
......@@ -94,13 +77,13 @@
_collectionView.hidden = NO;
if ([[_viewModel fetchDataSuccess] boolValue]) {
if ([[self.viewModel dataArray] count] == 0 && [self.viewModel fetchDataNilMsg]) {
[self showEmptyView:OCEmptyViewTypeEmpty];
[self showEmptyView:GMEmptyViewTypeEmpty];
} else {
[self hideEmptyView];
}
}else{
[self showEmptyView:OCEmptyViewTypeException];
[self showEmptyView:GMEmptyViewTypeException];
}
// 调用reloadData,并不会立即执行,而是下更新周期来了之后才可以。
......@@ -208,19 +191,7 @@
return _collectionViewLayout;
}
- (void)showEmptyView:(OCEmptyViewType)type {
_emptyView.type = type;
_emptyView.hidden = NO;
[self getEmptyText];
[_emptyView setNeedsLayout];
}
- (void)hideEmptyView {
_emptyView.hidden = YES;
}
#pragma mark - OCEmptyViewDelegate
- (void)emptyViewDidClickReload{
[self loadRemoteData];
}
......
......@@ -8,10 +8,9 @@
#import "WMBaseViewController.h"
#import <UITableView_FDTemplateLayoutCell/UITableView+FDTemplateLayoutCell.h>
#import "OCEmptyView.h"
#import "WMFetchDataViewModel.h"
@interface WMBaseListViewController : WMBaseViewController<UITableViewDelegate,UITableViewDataSource, OCEmptyViewDelegate>
@interface WMBaseListViewController : WMBaseViewController<UITableViewDelegate,UITableViewDataSource>
{
UITableView *_table;
......@@ -35,7 +34,7 @@
/** @brief viewModel*/
@property (nonatomic,strong) WMFetchDataViewModel *viewModel;
@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) OCEmptyView *emptyView;
/** @brief 控制当前VC的viewmodel是不是立即请求网络 **/
@property (nonatomic , assign) BOOL immediateLoad;
......@@ -77,16 +76,4 @@
* @since 6.0.0
*/
- (void)hideNavigationBar;
- (void)hideEmptyView;
/*!
* @author zhaiguojun, 16-06-28
*
* @brief 给子类设置空view的文案
*
* @param text
*
* @since 6.1.0
*/
- (NSString *)getEmptyText;
@end
......@@ -57,21 +57,6 @@
make.bottom.mas_equalTo(0);
}];
// baseList的EmptyView
_emptyView = [[OCEmptyView alloc] initWithFrame:CGRectZero];
_emptyView.hidden = YES;
if([self getEmptyText].length > 0){
_emptyView.tipText = [self getEmptyText];
}
_emptyView.delegate = self;
[self.view addSubview:_emptyView];
[_emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.top.mas_equalTo(0);
make.bottom.mas_equalTo(0);
}];
__weak __typeof(self)weakSelf = self;
if (_needHeaderRefresh) {
_table.mj_header = [GMRefreshHeader headerWithRefreshingBlock:^{
......@@ -188,12 +173,12 @@
[self hideLoading];
if ([[self.viewModel fetchDataSuccess] boolValue]) {
if ([[self.viewModel dataArray] count] == 0) {
[self showEmptyView:OCEmptyViewTypeEmpty];
[self showEmptyView:GMEmptyViewTypeEmpty];
}else {
[self hideEmptyView];
}
}else{
[self showEmptyView:OCEmptyViewTypeException];
[self showEmptyView:GMEmptyViewTypeException];
}
if (_table!=nil) {
......@@ -207,19 +192,6 @@
}
}
- (void)showEmptyView:(OCEmptyViewType)type {
_emptyView.type = type;
_emptyView.hidden = NO;
_emptyView.tipText = [self getEmptyText];
[_emptyView setNeedsUpdateConstraints];
}
- (void)hideEmptyView {
_emptyView.hidden = YES;
}
- (void)dealloc{
[self removeKVO];
// 因为fetchDataSuccess是在viewDidLoad中监听的,所以需要一个判断
......@@ -228,9 +200,8 @@
}
}
#pragma mark - OCEmptyViewDelegate
- (void)emptyViewDidClickReload{
#pragma mark - GMEmptyView
- (void)emptyViewDidClickReload {
[self loadRemoteData];
}
......@@ -240,6 +211,4 @@
}
return @"";
}
@end
......@@ -9,8 +9,9 @@
#import <UIKit/UIKit.h>
#import "OCNavigatioinBar.h"
#import <GMPhobos/GMPhobos-umbrella.h>
@import GMKit;
@interface WMBaseViewController : UIViewController <OCNavigatioinBarDelegate>
@interface WMBaseViewController : UIViewController <OCNavigatioinBarDelegate, GMEmptyViewDelegate>
@property (nonatomic, strong) OCNavigatioinBar *navigationBar;
/**
默认值为NO,表示导航栏自动被WMBaseViewController管理,永远在所有的view最上方。
......@@ -18,9 +19,27 @@
*/
@property (nonatomic, assign) BOOL controlNavigationByYou;
@property (nonatomic, strong) GMEmptyView *emptyView;
/**
* @brief 因为controller会有initWithCoder,init,initWithNib三种方式,为了避免子类代码的疏忽导致父类自定义init内容没有覆盖到,所以统一使用initController方法。需要调用super
*/
- (void)initController __attribute__((objc_requires_super));
- (void)pushViewController:(UIViewController *)controller;
#pragma mark - Empty
- (void)showEmptyView:(GMEmptyViewType)type;
- (void)hideEmptyView;
/*!
* @author zhaiguojun, 16-06-28
*
* @brief 给子类设置空view的文案
*
* @param text
*
* @since 6.1.0
*/
- (NSString *)getEmptyText;
- (void)emptyViewDidClickReload;
@end
......@@ -61,6 +61,20 @@
[self hideLeftButtonForRootController];
//保证一些网络请求需要接参数referer的时候referer是有值的
[self initReferer];
[self setupEmptyView];
}
- (void)setupEmptyView {
_emptyView = [[GMEmptyView alloc] initWithFrame:CGRectZero];
_emptyView.hidden = YES;
_emptyView.delegate = self;
[self.view addSubview:_emptyView];
[_emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.right.mas_equalTo(0);
make.top.mas_equalTo(0);
make.bottom.mas_equalTo(0);
}];
}
- (void)viewDidLayoutSubviews {
......@@ -156,4 +170,18 @@
[self dismissViewControllerAnimated:YES completion:nil];
}
}
#pragma mark - GMEmptyView
- (void)showEmptyView:(GMEmptyViewType)type {
_emptyView.type = type;
_emptyView.hidden = NO;
[self.view bringSubviewToFront:_emptyView];
}
- (void)hideEmptyView {
_emptyView.hidden = YES;
}
- (void)emptyViewDidClickReload {}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment