提交 94049834 编写于 作者: C CC

CCAutoTag push : 用UICollectionView简化处理

上级 8167f5ec
......@@ -14,9 +14,9 @@
#import "DoraemonDefine.h"
#import "DoraemonHomeWindow.h"
#import "DoraemonStatusBarViewController.h"
@interface DoraemonEntryView()
@property (nonatomic, assign) BOOL isOpen;
@property (nonatomic, strong) UIButton *entryBtn;
@property (nonatomic, assign) CGFloat kEntryViewSize;
......@@ -24,6 +24,18 @@
@implementation DoraemonEntryView
- (UIButton *)entryBtn {
if (!_entryBtn) {
_entryBtn = [[UIButton alloc] initWithFrame:self.bounds];
_entryBtn.backgroundColor = [UIColor clearColor];
[_entryBtn setImage:[UIImage doraemon_imageNamed:@"doraemon_logo"] forState:UIControlStateNormal];
_entryBtn.layer.cornerRadius = 20.;
[_entryBtn addTarget:self action:@selector(entryClick:) forControlEvents:UIControlEventTouchUpInside];
}
return _entryBtn;
}
- (instancetype)init{
_kEntryViewSize = 58;
CGFloat x = self.startingPosition.x;
......@@ -54,13 +66,7 @@
}
}
UIButton *entryBtn = [[UIButton alloc] initWithFrame:self.bounds];
entryBtn.backgroundColor = [UIColor clearColor];
[entryBtn setImage:[UIImage doraemon_imageNamed:@"doraemon_logo"] forState:UIControlStateNormal];
entryBtn.layer.cornerRadius = 20.;
[entryBtn addTarget:self action:@selector(entryClick:) forControlEvents:UIControlEventTouchUpInside];
[self.rootViewController.view addSubview:entryBtn];
_entryBtn = entryBtn;
[self.rootViewController.view addSubview:self.entryBtn];
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];
[self addGestureRecognizer:pan];
}
......
//
// DoraemonHomeCell.h
// DoraemonKit
//
// Created by dengyouhua on 2019/9/4.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface DoraemonHomeCell : UICollectionViewCell
- (void)update:(NSString *)image name:(NSString *)name;
@end
NS_ASSUME_NONNULL_END
//
// DoraemonHomeCell.m
// DoraemonKit
//
// Created by dengyouhua on 2019/9/4.
//
#import "DoraemonHomeCell.h"
@interface DoraemonHomeCell()
@property (nonatomic, strong) UIImageView *icon;
@property (nonatomic, strong) UILabel *name;
@end
@implementation DoraemonHomeCell
- (UIImageView *)icon {
if (!_icon) {
CGFloat size = 34;
_icon = [[UIImageView alloc] initWithFrame:CGRectMake((self.doraemon_width - size) / 2.0, 4, size, size)];
}
return _icon;
}
- (UILabel *)name {
if (!_name) {
CGFloat height = 16;
_name = [[UILabel alloc] initWithFrame:CGRectMake(0, self.doraemon_height - height - 4, self.doraemon_width, height)];
_name.textAlignment = NSTextAlignmentCenter;
_name.font = [UIFont systemFontOfSize:12];
_name.adjustsFontSizeToFitWidth = YES;
}
return _name;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
[self addSubview:self.icon];
[self addSubview:self.name];
}
return self;
}
- (void)update:(NSString *)image name:(NSString *)name {
self.icon.image = [UIImage doraemon_imageNamed:image];
self.name.text = name;
}
@end
//
// DoraemonHomeCloseCell.h
// DoraemonKit
//
// Created by dengyouhua on 2019/9/4.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface DoraemonHomeCloseCell : UICollectionViewCell
@end
NS_ASSUME_NONNULL_END
//
// DoraemonHomeCloseCell.m
// DoraemonKit
//
// Created by dengyouhua on 2019/9/4.
//
#import "DoraemonHomeCloseCell.h"
#import "DoraemonManager.h"
#import "DoraemonUtil.h"
#import "DoraemonHomeWindow.h"
@interface DoraemonHomeCloseCell ()
@property (nonatomic, strong) UIButton *closeButton;
@end
@implementation DoraemonHomeCloseCell
- (void)closeButtonHandle{
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:DoraemonLocalizedString(@"提示") message:DoraemonLocalizedString(@"Doraemon关闭之后需要重启App才能重新打开") preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:nil];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:DoraemonLocalizedString(@"确定") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[DoraemonManager shareInstance] hiddenDoraemon];
}];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[[DoraemonUtil topViewControllerForKeyWindow] presentViewController:alertController animated:YES completion:nil];
[[DoraemonHomeWindow shareInstance] hide];
}
- (UIButton *)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
_closeButton.backgroundColor = [UIColor whiteColor];
[_closeButton setTitle:DoraemonLocalizedString(@"关闭DoraemonKit") forState:UIControlStateNormal];
[_closeButton setTitleColor:[UIColor doraemon_colorWithString:@"#CC3A4B"] forState:UIControlStateNormal];
[_closeButton addTarget:self action:@selector(closeButtonHandle) forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self addSubview:self.closeButton];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat x = 5;
self.closeButton.frame = CGRectMake(x, x, self.doraemon_width - x * 2, 50);
}
@end
//
// DoraemonHomeFootCell.h
// DoraemonKit
//
// Created by dengyouhua on 2019/9/4.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface DoraemonHomeFootCell : UICollectionReusableView
@end
NS_ASSUME_NONNULL_END
//
// DoraemonHomeFootCell.m
// DoraemonKit
//
// Created by dengyouhua on 2019/9/4.
//
#import "DoraemonHomeFootCell.h"
@implementation DoraemonHomeFootCell
@end
//
// DoraemonHomeHeadCell.h
// DoraemonKit
//
// Created by dengyouhua on 2019/9/4.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface DoraemonHomeHeadCell : UICollectionReusableView
@property (nonatomic, strong) UILabel *title;
@end
NS_ASSUME_NONNULL_END
//
// DoraemonHomeHeadCell.m
// DoraemonKit
//
// Created by dengyouhua on 2019/9/4.
//
#import "DoraemonHomeHeadCell.h"
@implementation DoraemonHomeHeadCell
- (UILabel *)title {
if (!_title) {
_title = [UILabel new];
}
return _title;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor whiteColor];
[self addSubview:self.title];
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
self.title.frame = UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(0, 15, 0, 15));
}
@end
//
// DoraemonHomeEntry.h
// DoraemonKit
//
// Created by dengyouhua on 2019/9/4.
//
#import "DoraemonBaseViewController.h"
NS_ASSUME_NONNULL_BEGIN
/**
* DoraemonHomeEntry | 新主界面入口
*/
@interface DoraemonHomeEntry : DoraemonBaseViewController
@end
NS_ASSUME_NONNULL_END
//
// DoraemonHomeEntry.m
// DoraemonKit
//
// Created by dengyouhua on 2019/9/4.
//
#import "DoraemonHomeEntry.h"
#import "UIView+Doraemon.h"
#import "DoraemonUtil.h"
#import "UIColor+Doraemon.h"
#import "DoraemonManager.h"
#import "DoraemonPluginProtocol.h"
#import "DoraemonHomeWindow.h"
#import "DoraemonDefine.h"
#import "DoraemonHomeCell.h"
#import "DoraemonHomeHeadCell.h"
#import "DoraemonHomeFootCell.h"
#import "DoraemonHomeCloseCell.h"
static NSString *DoraemonHomeCellID = @"DoraemonHomeCellID";
static NSString *DoraemonHomeHeadCellID = @"DoraemonHomeHeadCellID";
static NSString *DoraemonHomeFootCellID = @"DoraemonHomeFootCellID";
static NSString *DoraemonHomeCloseCellID = @"DoraemonHomeCloseCellID";
@interface DoraemonHomeEntry () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic,strong) NSMutableArray *dataArray;
@end
@implementation DoraemonHomeEntry
- (UICollectionView *)collectionView {
if (!_collectionView) {
UICollectionViewFlowLayout *fl = [[UICollectionViewFlowLayout alloc] init];
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:fl];
_collectionView.backgroundColor = [UIColor whiteColor];
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerClass:[DoraemonHomeCell class] forCellWithReuseIdentifier:DoraemonHomeCellID];
[_collectionView registerClass:[DoraemonHomeCloseCell class] forCellWithReuseIdentifier:DoraemonHomeCloseCellID];
[_collectionView registerClass:[DoraemonHomeHeadCell class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:DoraemonHomeHeadCellID];
[_collectionView registerClass:[DoraemonHomeFootCell class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:DoraemonHomeFootCellID];
}
return _collectionView;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section < _dataArray.count) {
return CGSizeMake(80, 64);
} else {
return CGSizeMake(DoraemonScreenHeight, 60);
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
if (section < _dataArray.count) {
return CGSizeMake(DoraemonScreenHeight, 44);
} else {
return CGSizeMake(DoraemonScreenHeight, 0);
}
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
return CGSizeMake(DoraemonScreenHeight, 20);
}
- (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath {
view.layer.zPosition = 0.0;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return _dataArray.count + 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (section < self.dataArray.count) {
NSDictionary *dict = _dataArray[section];
NSArray *pluginArray = dict[@"pluginArray"];
return pluginArray.count;
} else {
return 1;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
DoraemonHomeCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:DoraemonHomeCellID forIndexPath:indexPath];
NSInteger row = indexPath.row;
NSInteger section = indexPath.section;
if (section < _dataArray.count) {
NSDictionary *dict = _dataArray[section];
NSArray *pluginArray = dict[@"pluginArray"];
NSDictionary *item = pluginArray[row];
[cell update:item[@"icon"] name:item[@"name"]];
return cell;
} else {
DoraemonHomeCloseCell *closeCell = [collectionView dequeueReusableCellWithReuseIdentifier:DoraemonHomeCloseCellID forIndexPath: indexPath];
return closeCell;
}
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
UICollectionReusableView *view = nil;
if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
DoraemonHomeHeadCell *head = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:DoraemonHomeHeadCellID forIndexPath:indexPath];
head.title.text = @"";
NSInteger section = indexPath.section;
if (section < _dataArray.count) {
NSDictionary *dict = _dataArray[section];
head.title.text = dict[@"moduleName"];
}
view = head;
} else if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {
DoraemonHomeFootCell *foot = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:DoraemonHomeFootCellID forIndexPath:indexPath];
foot.backgroundColor = [UIColor doraemon_colorWithString:@"#F4F5F6"];
view = foot;
}
return view;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSInteger section = indexPath.section;
if (section < self.dataArray.count) {
NSDictionary *dict = _dataArray[section];
NSArray *pluginArray = dict[@"pluginArray"];
NSDictionary *itemData = pluginArray[indexPath.row];
NSString *pluginName = itemData[@"pluginName"];
if(pluginName){
Class pluginClass = NSClassFromString(pluginName);
id<DoraemonPluginProtocol> plugin = [[pluginClass alloc] init];
if ([plugin respondsToSelector:@selector(pluginDidLoad)]) {
[plugin pluginDidLoad];
}
if ([plugin respondsToSelector:@selector(pluginDidLoad:)]) {
[plugin pluginDidLoad:(NSDictionary *)itemData];
}
void (^handleBlock)(NSDictionary *itemData) = itemData[@"handleBlock"];
if (handleBlock) {
handleBlock(itemData);
}
}
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
_dataArray = [DoraemonManager shareInstance].dataArray;
[self.view addSubview:self.collectionView];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
+ (UIEdgeInsets)safeAreaInset:(UIView *)view {
if (@available(iOS 11.0, *)) {
return view.safeAreaInsets;
}
return UIEdgeInsetsZero;
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
// self.collectionView.frame = self.view.frame;
UIEdgeInsets safeAreaInsets = [self.class safeAreaInset:self.view];
CGFloat height = self.view.doraemon_height - safeAreaInsets.left - safeAreaInsets.right;
// self.collectionView.frame = CGRectMake(safeAreaInsets.left, safeAreaInsets.top, self.view.doraemon_width, self.view.doraemon_height);
// self.collectionView.frame = CGRectMake(safeAreaInsets.left, safeAreaInsets.top, self.view.doraemon_width, height);
self.collectionView.frame = self.view.frame;
}
@end
......@@ -8,7 +8,7 @@
#import "DoraemonHomeWindow.h"
#import "DoraemonDefine.h"
#import "UIColor+Doraemon.h"
#import "DoraemonHomeViewController.h"
#import "DoraemonHomeEntry.h"
@implementation DoraemonHomeWindow
......@@ -37,7 +37,7 @@
}
- (void)show{
DoraemonHomeViewController *vc = [[DoraemonHomeViewController alloc] init];
DoraemonHomeEntry *vc = [[DoraemonHomeEntry alloc] init];
[self setRootVc:vc];
self.hidden = NO;
......
......@@ -24,33 +24,33 @@ PODS:
- CocoaLumberjack (3.5.3):
- CocoaLumberjack/Core (= 3.5.3)
- CocoaLumberjack/Core (3.5.3)
- DoraemonKit/Core (1.2.2):
- DoraemonKit/Core (1.2.3):
- BSBacktraceLogger
- fishhook
- PNChart
- DoraemonKit/WithDatabase (1.2.2):
- DoraemonKit/WithDatabase (1.2.3):
- BSBacktraceLogger
- DoraemonKit/Core
- fishhook
- PNChart
- YYDebugDatabase
- DoraemonKit/WithGPS (1.2.2):
- DoraemonKit/WithGPS (1.2.3):
- BSBacktraceLogger
- DoraemonKit/Core
- fishhook
- PNChart
- DoraemonKit/WithLoad (1.2.2):
- DoraemonKit/WithLoad (1.2.3):
- BSBacktraceLogger
- DoraemonKit/Core
- fishhook
- PNChart
- DoraemonKit/WithLogger (1.2.2):
- DoraemonKit/WithLogger (1.2.3):
- BSBacktraceLogger
- CocoaLumberjack
- DoraemonKit/Core
- fishhook
- PNChart
- DoraemonKit/WithWeex (1.2.2):
- DoraemonKit/WithWeex (1.2.3):
- BSBacktraceLogger
- DoraemonKit/Core
- fishhook
......@@ -113,7 +113,7 @@ SPEC CHECKSUMS:
AFNetworking: cb8d14a848e831097108418f5d49217339d4eb60
BSBacktraceLogger: 06b983ee93a9f87d957960e9c73d660d5966b447
CocoaLumberjack: 2f44e60eb91c176d471fdba43b9e3eae6a721947
DoraemonKit: ea50d30db95bd7ce978e964b2bb90c588a19a2a3
DoraemonKit: c1e675735a94db6ca7ad6ffac256d6baddc00afb
fishhook: ea19933abfe8f2f52c55fd8b6e2718467d3ebc89
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
GCDWebServer: ead88cd14596dd4eae4f5830b8877c87c8728990
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册