Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
GMBase
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
GMBase
Commits
96747113
Commit
96747113
authored
Apr 19, 2017
by
汪洋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
删除不需要的hud代码,使用GMHud代替
parent
710c30e0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
287 additions
and
187 deletions
+287
-187
UIViewController+HUD.h
GMBase/Classes/UIViewController+HUD.h
+0
-47
UIViewController+HUD.m
GMBase/Classes/UIViewController+HUD.m
+0
-140
WMBaseCollectionController.h
GMBase/Classes/WMBaseCollectionController.h
+52
-0
WMBaseCollectionController.m
GMBase/Classes/WMBaseCollectionController.m
+235
-0
No files found.
GMBase/Classes/UIViewController+HUD.h
deleted
100644 → 0
View file @
710c30e0
//
// UIViewController+HUD.h
// Pods
//
// Created by wangyang on 16/7/11.
//
//
#import <UIKit/UIKit.h>
#import <MBProgressHUD/MBProgressHUD.h>
NS_ASSUME_NONNULL_BEGIN
@interface
UIViewController
(
HUD
)
/**
* @brief 显示加载动画
* @param text 加载动画文字
*/
-
(
void
)
showLoading
:(
nullable
NSString
*
)
text
;
/**
* @brief 显示隐藏加载
* @param text 警告文字
*/
-
(
void
)
hideLoading
;
/**
* @brief 显示完成信息,1秒后消失
* @param text 文字
*/
-
(
void
)
showComplete
:(
NSString
*
)
text
;
/**
* @brief 显示警告或错误信息,1秒后消失
* @param text 警告文字
*/
-
(
void
)
showWarning
:(
NSString
*
)
text
;
/**
* @brief toast
*
* @param text 仅显示文字提示
*/
-
(
void
)
toast
:(
NSString
*
)
text
;
-
(
void
)
toastInView
:(
NSString
*
)
text
;
@end
NS_ASSUME_NONNULL_END
\ No newline at end of file
GMBase/Classes/UIViewController+HUD.m
deleted
100644 → 0
View file @
710c30e0
//
// UIViewController+HUD.m
// Pods
//
// Created by wangyang on 16/7/11.
//
//
#import "UIViewController+HUD.h"
#import <objc/runtime.h>
@interface
UIViewController
(
HUD
)
@property
(
nonatomic
,
strong
)
MBProgressHUD
*
hud
;
@end
@implementation
UIViewController
(
HUD
)
-
(
MBProgressHUD
*
)
hud
{
return
objc_getAssociatedObject
(
self
,
@selector
(
hud
));
}
-
(
void
)
setHud
:
(
MBProgressHUD
*
)
hud
{
objc_setAssociatedObject
(
self
,
@selector
(
hud
),
hud
,
OBJC_ASSOCIATION_RETAIN_NONATOMIC
);
}
-
(
NSTimeInterval
)
timeForHUDString
:
(
NSString
*
)
string
{
NSInteger
count
=
string
.
length
;
if
(
count
<
8
)
{
return
1
.
0
;
}
else
if
(
count
>=
8
&&
count
<
15
)
{
return
2
;
}
else
if
(
count
>=
15
&&
count
<
25
)
{
return
3
;
}
else
{
return
4
;
}
}
-
(
void
)
showComplete
:
(
NSString
*
)
text
{
[
self
hideLoading
];
self
.
hud
=
[[
MBProgressHUD
alloc
]
initWithView
:
self
.
view
];
[
self
.
view
addSubview
:
self
.
hud
];
self
.
hud
.
customView
=
[[
UIImageView
alloc
]
initWithImage
:[
UIImage
imageNamed
:
@"ToastFinish"
]];
self
.
hud
.
mode
=
MBProgressHUDModeCustomView
;
self
.
hud
.
removeFromSuperViewOnHide
=
YES
;
self
.
hud
.
delegate
=
self
;
if
(
text
!=
nil
&&
text
.
length
>
20
)
{
self
.
hud
.
detailsLabelText
=
text
;
}
else
{
self
.
hud
.
labelText
=
text
;
}
[
self
.
hud
show
:
YES
];
NSTimeInterval
timeInterval
=
[
self
timeForHUDString
:
text
];
[
self
.
hud
hide
:
YES
afterDelay
:
timeInterval
];
}
-
(
void
)
showWarning
:
(
NSString
*
)
text
{
[
self
hideLoading
];
self
.
hud
=
[[
MBProgressHUD
alloc
]
initWithView
:
self
.
view
];
[
self
.
view
addSubview
:
self
.
hud
];
self
.
hud
.
removeFromSuperViewOnHide
=
YES
;
self
.
hud
.
customView
=
[[
UIImageView
alloc
]
initWithImage
:[
UIImage
imageNamed
:
@"ToastWarn"
]];
// Set custom view mode
self
.
hud
.
mode
=
MBProgressHUDModeCustomView
;
self
.
hud
.
delegate
=
self
;
if
(
text
!=
nil
&&
text
.
length
>
20
)
{
self
.
hud
.
detailsLabelText
=
text
;
}
else
{
self
.
hud
.
labelText
=
text
;
}
[
self
.
hud
show
:
YES
];
NSTimeInterval
timeInterval
=
[
self
timeForHUDString
:
text
];
[
self
.
hud
hide
:
YES
afterDelay
:
timeInterval
];
}
-
(
void
)
showLoading
:
(
NSString
*
)
text
{
[
self
hideLoading
];
self
.
hud
=
[[
MBProgressHUD
alloc
]
initWithView
:
self
.
view
];
[
self
.
view
addSubview
:
self
.
hud
];
self
.
hud
.
removeFromSuperViewOnHide
=
YES
;
self
.
hud
.
mode
=
MBProgressHUDModeIndeterminate
;
self
.
hud
.
delegate
=
self
;
self
.
hud
.
labelText
=
text
;
[
self
.
hud
show
:
YES
];
UIButton
*
button
=
[[
self
valueForKey
:
@"navigationBar"
]
valueForKey
:
@"rightButton"
];
button
.
enabled
=
NO
;
}
-
(
void
)
toast
:
(
NSString
*
)
text
{
[
self
hideLoading
];
if
(
text
.
length
==
0
)
{
return
;
}
MBProgressHUD
*
hud
=
[
MBProgressHUD
showHUDAddedTo
:[
UIApplication
sharedApplication
].
keyWindow
animated
:
YES
];
hud
.
mode
=
MBProgressHUDModeText
;
hud
.
userInteractionEnabled
=
YES
;
if
(
text
!=
nil
&&
text
.
length
>
18
)
{
hud
.
detailsLabelText
=
text
;
}
else
{
hud
.
labelText
=
text
;
}
hud
.
margin
=
10
.
f
;
hud
.
removeFromSuperViewOnHide
=
YES
;
NSTimeInterval
timeInterval
=
[
self
timeForHUDString
:
text
];
[
hud
hide
:
YES
afterDelay
:
timeInterval
];
}
-
(
void
)
toastInView
:
(
NSString
*
)
text
{
if
(
text
.
length
==
0
)
{
return
;
}
[
self
hideLoading
];
MBProgressHUD
*
hud
=
[
MBProgressHUD
showHUDAddedTo
:
self
.
view
animated
:
YES
];
hud
.
mode
=
MBProgressHUDModeText
;
hud
.
userInteractionEnabled
=
YES
;
if
(
text
!=
nil
&&
text
.
length
>
18
)
{
hud
.
detailsLabelText
=
text
;
}
else
{
hud
.
labelText
=
text
;
}
hud
.
margin
=
10
.
f
;
hud
.
removeFromSuperViewOnHide
=
YES
;
[
hud
hide
:
YES
afterDelay
:
1
.
0
];
}
-
(
void
)
hideLoading
{
[
self
.
hud
hide
:
YES
];
UIButton
*
button
=
[[
self
valueForKey
:
@"navigationBar"
]
valueForKey
:
@"rightButton"
];
button
.
enabled
=
YES
;
}
@end
GMBase/Classes/WMBaseCollectionController.h
0 → 100644
View file @
96747113
//
// WMBaseCollectionController.h
// Gengmei
//
// Created by wangyang on 9/2/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import "WMBaseViewController.h"
#import "WMFetchDataViewModel.h"
#import "OCEmptyView.h"
@interface
WMBaseCollectionController
:
WMBaseViewController
<
UICollectionViewDelegateFlowLayout
,
UICollectionViewDataSource
>
{
BOOL
_needHeaderRefresh
;
BOOL
_needFooterRefresh
;
WMFetchDataViewModel
*
_viewModel
;
UICollectionView
*
_collectionView
;
UICollectionViewLayout
*
_collectionViewLayout
;
}
@property
(
nonatomic
,
strong
)
WMFetchDataViewModel
*
viewModel
;
/** @brief 控制当前VC的viewmodel是不是立即请求网络 **/
@property
(
nonatomic
,
assign
)
BOOL
immediateLoad
;
/**
* @brief 默认大小是self.view.bounds
*/
@property
(
nonatomic
,
strong
)
UICollectionView
*
collectionView
;
@property
(
nonatomic
,
strong
)
OCEmptyView
*
emptyView
;
/**
* @brief 默认返回一个 flowLayout
@code
minimumLineSpacing = 0;
minimumInteritemSpacing = 0;
itemSize = CGSizeMake(50, 50);
@endcode
详见具体实现
*/
@property
(
nonatomic
,
strong
)
UICollectionViewLayout
*
collectionViewLayout
;
-
(
void
)
updateOtherUIData
__attribute__
((
objc_requires_super
));
-
(
void
)
observeValueForKeyPath
:(
NSString
*
)
keyPath
ofObject
:(
id
)
object
change
:(
NSDictionary
*
)
change
context
:(
void
*
)
context
__attribute__
((
objc_requires_super
));
-
(
void
)
refreshList
;
-
(
void
)
headerRereshing
;
-
(
void
)
footerRereshing
;
-
(
void
)
hideNavigationBar
;
-
(
void
)
hideEmptyView
;
-
(
NSString
*
)
getEmptyText
;
@end
GMBase/Classes/WMBaseCollectionController.m
0 → 100644
View file @
96747113
//
// WMBaseCollectionController.m
// Gengmei
//
// Created by wangyang on 9/2/15.
// Copyright (c) 2015 Wanmeichuangyi. All rights reserved.
//
#import "WMBaseCollectionController.h"
#import <GMRefresh/GMRefreshFooter.h>
#import <GMRefresh/GMRefreshHeader.h>
#import <Masonry/Masonry.h>
@interface
WMBaseCollectionController
()
<
OCEmptyViewDelegate
>
@end
@implementation
WMBaseCollectionController
@synthesize
viewModel
=
_viewModel
;
@synthesize
collectionView
=
_collectionView
;
@synthesize
collectionViewLayout
=
_collectionViewLayout
;
-
(
void
)
initController
{
[
super
initController
];
self
.
viewModel
=
[[
WMFetchDataViewModel
alloc
]
init
];
_needHeaderRefresh
=
YES
;
_needFooterRefresh
=
YES
;
_immediateLoad
=
YES
;
}
-
(
void
)
viewDidLoad
{
[
super
viewDidLoad
];
[
self
addKVO
];
[
self
.
view
addSubview
:
self
.
collectionView
];
[
_collectionView
mas_makeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
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
:
^
{
[
weakSelf
headerRereshing
];
}];
}
if
(
_needFooterRefresh
)
{
_collectionView
.
mj_footer
=
[
GMRefreshFooter
footerWithRefreshingBlock
:
^
{
[
weakSelf
footerRereshing
];
}];
}
//获取数据
if
(
_immediateLoad
)
{
[
self
loadRemoteData
];
}
}
-
(
void
)
hideNavigationBar
{
self
.
navigationBar
.
hidden
=
YES
;
[
_collectionView
mas_updateConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
top
.
mas_equalTo
(
0
);
}];
}
-
(
void
)
addKVO
{
[
self
.
viewModel
addObserver
:
self
forKeyPath
:
@"fetchDataSuccess"
options
:
NSKeyValueObservingOptionNew
context
:
NULL
];
}
-
(
void
)
observeValueForKeyPath
:
(
NSString
*
)
keyPath
ofObject
:
(
id
)
object
change
:
(
NSDictionary
*
)
change
context
:
(
void
*
)
context
{
if
([
keyPath
isEqualToString
:
@"fetchDataSuccess"
]
&&
object
==
self
.
viewModel
)
{
[
self
hideLoading
];
_collectionView
.
hidden
=
NO
;
if
([[
_viewModel
fetchDataSuccess
]
boolValue
])
{
if
([[
self
.
viewModel
dataArray
]
count
]
==
0
&&
[
self
.
viewModel
fetchDataNilMsg
])
{
[
self
showEmptyView
:
OCEmptyViewTypeEmpty
];
}
else
{
[
self
hideEmptyView
];
}
}
else
{
[
self
showEmptyView
:
OCEmptyViewTypeException
];
}
// 调用reloadData,并不会立即执行,而是下更新周期来了之后才可以。
// 将 endRefreshing 与 endRefreshing 放到后面的好处就是此时可以利用 updateOtherUIData 做点额外的事。比如判断mj_header.isRefreshing
[
self
updateOtherUIData
];
if
(
_collectionView
)
{
[
_collectionView
reloadData
];
[
_collectionView
.
mj_header
endRefreshing
];
[
_collectionView
.
mj_footer
endRefreshing
];
}
}
}
-
(
void
)
dealloc
{
[
self
removeKVO
];
if
(
self
.
isViewLoaded
)
{
[
self
.
viewModel
removeObserver
:
self
forKeyPath
:
@"fetchDataSuccess"
];
}
}
-
(
void
)
removeKVO
{
}
/**
* @brief 下拉刷新
*/
-
(
void
)
headerRereshing
{
[
self
.
viewModel
handleHeaderRefreshing
];
}
/**
* @brief 上拉加载更多
*/
-
(
void
)
footerRereshing
{
[
self
.
viewModel
handleFooterRereshing
];
}
-
(
void
)
updateOtherUIData
{
// 如果 contentSize 高没有 _collectionView.bounds.size.height 这个大,就强制设置一下,这样 collectionView 还能下拉滑动,以保证上拉、下拉正常使用
if
(
_collectionView
.
contentSize
.
height
<=
_collectionView
.
bounds
.
size
.
height
)
{
_collectionView
.
contentSize
=
CGSizeMake
(
_collectionView
.
bounds
.
size
.
width
,
_collectionView
.
bounds
.
size
.
height
);
}
}
-
(
void
)
refreshList
{
[
self
.
viewModel
setStartNum
:
0
];
[[
self
.
viewModel
dataArray
]
removeAllObjects
];
[
_collectionView
reloadData
];
[
self
loadRemoteData
];
}
-
(
void
)
loadRemoteData
{
[
self
showLoading
:
nil
];
[
self
.
viewModel
fetchRemoteData
];
}
-
(
void
)
didMoveToParentViewController
:
(
UIViewController
*
)
parent
{
[
super
didMoveToParentViewController
:
parent
];
if
(
parent
!=
nil
&&
!
[
parent
isKindOfClass
:[
UINavigationController
class
]])
{
[
_collectionView
mas_remakeConstraints
:
^
(
MASConstraintMaker
*
make
)
{
make
.
edges
.
equalTo
(
self
.
view
).
insets
(
UIEdgeInsetsMake
(
0
,
0
,
0
,
0
));
}];
}
}
#pragma mark - UICollectionViewDelegate and UICollectionViewDataSource
-
(
NSInteger
)
collectionView
:
(
UICollectionView
*
)
collectionView
numberOfItemsInSection
:
(
NSInteger
)
section
{
return
self
.
viewModel
.
dataArray
.
count
;
}
-
(
UICollectionViewCell
*
)
collectionView
:
(
UICollectionView
*
)
collectionView
cellForItemAtIndexPath
:
(
NSIndexPath
*
)
indexPath
{
return
nil
;
}
#pragma mark - Setter and Getter
-
(
UICollectionView
*
)
collectionView
{
if
(
!
_collectionView
)
{
_collectionView
=
[[
UICollectionView
alloc
]
initWithFrame
:
self
.
view
.
bounds
collectionViewLayout
:
self
.
collectionViewLayout
];
_collectionView
.
backgroundColor
=
[
UIColor
whiteColor
];
_collectionView
.
delegate
=
self
;
_collectionView
.
alwaysBounceVertical
=
YES
;
_collectionView
.
dataSource
=
self
;
_collectionView
.
hidden
=
YES
;
}
return
_collectionView
;
}
-
(
UICollectionViewLayout
*
)
collectionViewLayout
{
UICollectionViewFlowLayout
*
layout
=
[[
UICollectionViewFlowLayout
alloc
]
init
];
layout
.
minimumLineSpacing
=
3
;
layout
.
minimumInteritemSpacing
=
3
;
layout
.
itemSize
=
CGSizeMake
(
50
,
50
);
_collectionViewLayout
=
layout
;
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
];
}
-
(
NSString
*
)
getEmptyText
{
if
(
self
.
viewModel
.
message
.
length
>
0
)
{
return
self
.
viewModel
.
message
;
}
return
@""
;
}
@end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment