@@ -9,6 +9,7 @@
# import "BMLongPressDragCellCollectionView.h"
# import "UICollectionViewLeftAlignedLayout.h"
# import "KBMyKeyboardCell.h"
# import "KBAlert.h"
// / 复 用 标 识
static NSString * const kKBMyKeyboardCellId = @ "kKBMyKeyboardCellId" ;
@@ -24,6 +25,7 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
@ property ( nonatomic , strong ) UIView * sheetView ; // 底 部 白 色 容 器 ( 圆 角 )
@ property ( nonatomic , strong ) BMLongPressDragCellCollectionView * collectionView ; // 可 拖 拽 的 列 表
@ property ( nonatomic , strong ) UIButton * saveButton ; // 保 存 按 钮
@ property ( nonatomic , strong ) UIImageView * bgImageView ; // 背 景
// 数 据 源 ( 必 须 是 二 维 数 组 , 库 内 部 会 在 拖 动 时 直 接 调 整 顺 序 )
@ property ( nonatomic , strong ) NSMutableArray < NSMutableArray < NSDictionary * > * > * dataSourceArray ; // { emoji , title }
@@ -39,13 +41,18 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
- ( void ) viewDidLoad {
[ super viewDidLoad ] ;
self . view . backgroundColor = [ UIColor colorWithHex : 0 xF6F8F9 ] ;
self . navigationController . title = @ "My KeyBoard" ;
self . kb_navView . backgroundColor = [ UIColor clearColor ] ;
self . kb_titleLabel . text = @ "My KeyBoard" ;
// 布 局 视 图
[ self . view insertSubview : self . bgImageView belowSubview : self . kb_navView ] ;
[ self . view addSubview : self . sheetView ] ;
[ self . sheetView addSubview : self . collectionView ] ;
[ self . view addSubview : self . saveButton ] ;
[ self . bgImageView mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
make . top . left . right . equalTo ( self . view ) ;
make . height . mas_equalTo ( 323 ) ;
} ] ;
[ self . sheetView mas_makeConstraints : ^ ( MASConstraintMaker * make ) {
make . left . right . equalTo ( self . view ) ;
make . top . equalTo ( self . view ) . offset ( KB_NAV _TOTAL _HEIGHT + 60 ) ;
@@ -149,6 +156,46 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
KBMyKeyboardCell * cell = [ collectionView dequeueReusableCellWithReuseIdentifier : kKBMyKeyboardCellId forIndexPath : indexPath ] ;
NSDictionary * d = self . dataSourceArray [ indexPath . section ] [ indexPath . item ] ;
[ cell configEmoji : d [ @ "emoji" ] title : d [ @ "title" ] ] ;
__weak typeof ( self ) weakSelf = self ;
__weak typeof ( collectionView ) weakCV = collectionView ;
cell . onMinusTapped = ^ ( KBMyKeyboardCell * _Nonnull tappedCell ) {
__strong typeof ( weakSelf ) self = weakSelf ;
if ( ! self ) { return ; }
NSIndexPath * tapIndexPath = [ weakCV indexPathForCell : tappedCell ] ;
if ( ! tapIndexPath ) { return ; }
// [ KBAlert confirmTitle : @ "删除该标签?" message : @ "删除后不可恢复" completion : ^ ( BOOL ok ) {
// if ( ! ok ) { return ; }
// // 更 新 数 据 源 并 删 除 item
// if ( tapIndexPath . section < self . dataSourceArray . count ) {
// NSMutableArray * section = self . dataSourceArray [ tapIndexPath . section ] ;
// if ( tapIndexPath . item < section . count ) {
// [ section removeObjectAtIndex : tapIndexPath . item ] ;
// [ self . collectionView performBatchUpdates : ^ {
// [ self . collectionView deleteItemsAtIndexPaths : @ [ tapIndexPath ] ] ;
// } completion : nil ] ;
// }
// }
// } ] ;
[ KBAlert confirmTitle : @ "删除该标签?"
message : @ "删除后不可恢复"
ok : @ "确定"
cancel : @ "取消"
okColor : [ UIColor redColor ]
cancelColor : [ UIColor blackColor ]
completion : ^ ( BOOL ok ) {
if ( ! ok ) { return ; }
// 更 新 数 据 源 并 删 除 item
if ( tapIndexPath . section < self . dataSourceArray . count ) {
NSMutableArray * section = self . dataSourceArray [ tapIndexPath . section ] ;
if ( tapIndexPath . item < section . count ) {
[ section removeObjectAtIndex : tapIndexPath . item ] ;
[ self . collectionView performBatchUpdates : ^ {
[ self . collectionView deleteItemsAtIndexPaths : @ [ tapIndexPath ] ] ;
} completion : nil ] ;
}
}
} ] ;
} ;
return cell ;
}
@@ -237,4 +284,12 @@ static NSString * const kKBMyKeyboardCellId = @"kKBMyKeyboardCellId";
return _saveButton ;
}
- ( UIImageView * ) bgImageView {
if ( ! _bgImageView ) {
_bgImageView = [ [ UIImageView alloc ] init ] ;
_bgImageView . image = [ UIImage imageNamed : @ "my_keyboard_bg" ] ;
}
return _bgImageView ;
}
@ end