1
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KBMyKeyBoardVC : UIViewController
|
||||
@interface KBMyKeyBoardVC : BaseViewController
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -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:0xF6F8F9];
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user