恢复默认皮肤
This commit is contained in:
@@ -37,6 +37,7 @@
|
|||||||
@interface KBSkinCenterVC () <UITableViewDelegate, UITableViewDataSource>
|
@interface KBSkinCenterVC () <UITableViewDelegate, UITableViewDataSource>
|
||||||
@property (nonatomic, strong) UITableView *tableView;
|
@property (nonatomic, strong) UITableView *tableView;
|
||||||
@property (nonatomic, copy) NSArray<NSDictionary *> *skins; // 每个元素即一套皮肤的 JSON(与后端约定格式一致)
|
@property (nonatomic, copy) NSArray<NSDictionary *> *skins; // 每个元素即一套皮肤的 JSON(与后端约定格式一致)
|
||||||
|
@property (nonatomic, strong) UIButton *resetButton;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation KBSkinCenterVC
|
@implementation KBSkinCenterVC
|
||||||
@@ -146,7 +147,7 @@
|
|||||||
self.skins = @[
|
self.skins = @[
|
||||||
@{
|
@{
|
||||||
@"id": @"local001",
|
@"id": @"local001",
|
||||||
@"name": @"本地001皮肤",
|
@"name": KBLocalized(@"本地001皮肤"),
|
||||||
// 关键:zip_url 写成 bundle:// 前缀 + 文件名
|
// 关键:zip_url 写成 bundle:// 前缀 + 文件名
|
||||||
@"zip_url": @"bundle://001.zip",
|
@"zip_url": @"bundle://001.zip",
|
||||||
|
|
||||||
@@ -164,6 +165,30 @@
|
|||||||
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
self.tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||||
self.tableView.delegate = self; self.tableView.dataSource = self;
|
self.tableView.delegate = self; self.tableView.dataSource = self;
|
||||||
[self.view addSubview:self.tableView];
|
[self.view addSubview:self.tableView];
|
||||||
|
|
||||||
|
// 底部添加“恢复默认皮肤”测试按钮
|
||||||
|
UIButton *reset = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||||
|
[reset setTitle:KBLocalized(@"恢复默认皮肤") forState:UIControlStateNormal];
|
||||||
|
reset.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
|
||||||
|
reset.layer.cornerRadius = 8.0;
|
||||||
|
reset.layer.borderWidth = 1.0;
|
||||||
|
reset.layer.borderColor = [UIColor colorWithWhite:0.85 alpha:1.0].CGColor;
|
||||||
|
[reset addTarget:self action:@selector(onResetDefault:) forControlEvents:UIControlEventTouchUpInside];
|
||||||
|
[self.view addSubview:reset];
|
||||||
|
self.resetButton = reset;
|
||||||
|
|
||||||
|
[reset mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||||
|
make.left.equalTo(self.view).offset(16);
|
||||||
|
make.right.equalTo(self.view).offset(-16);
|
||||||
|
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-16);
|
||||||
|
make.height.mas_equalTo(44);
|
||||||
|
}];
|
||||||
|
|
||||||
|
// 让 tableView 的内容区域避免被按钮遮挡
|
||||||
|
UIEdgeInsets inset = self.tableView.contentInset;
|
||||||
|
inset.bottom += 44 + 24; // 按钮高度 + 上下间距
|
||||||
|
self.tableView.contentInset = inset;
|
||||||
|
self.tableView.scrollIndicatorInsets = inset;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - UITableView
|
#pragma mark - UITableView
|
||||||
@@ -188,11 +213,18 @@
|
|||||||
if (idx < 0 || idx >= self.skins.count) return;
|
if (idx < 0 || idx >= self.skins.count) return;
|
||||||
NSDictionary *skin = self.skins[idx];
|
NSDictionary *skin = self.skins[idx];
|
||||||
if (!skin) return;
|
if (!skin) return;
|
||||||
// 默认按远程 Zip 模式测试;如需本地 bundle,请改为 KBSkinSourceModeLocalBundleZip。
|
|
||||||
[[KBSkinService shared] applySkinWithJSON:skin
|
[[KBSkinService shared] applySkinWithJSON:skin
|
||||||
fromViewController:self
|
fromViewController:self
|
||||||
mode:KBSkinSourceModeLocalBundleZip
|
mode:KBSkinSourceModeLocalBundleZip
|
||||||
completion:nil];
|
completion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)onResetDefault:(UIButton *)sender {
|
||||||
|
// 不需要皮肤 JSON,传空字典即可
|
||||||
|
[[KBSkinService shared] applySkinWithJSON:@{}
|
||||||
|
fromViewController:self
|
||||||
|
mode:KBSkinSourceModeResetToDefault
|
||||||
|
completion:nil];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ typedef NS_ENUM(NSUInteger, KBSkinSourceMode) {
|
|||||||
KBSkinSourceModeRemoteZip = 0,
|
KBSkinSourceModeRemoteZip = 0,
|
||||||
/// 本地 bundle Zip:从主 App bundle 中读取 zip_url 指定的 zip 文件并解压到 App Group
|
/// 本地 bundle Zip:从主 App bundle 中读取 zip_url 指定的 zip 文件并解压到 App Group
|
||||||
KBSkinSourceModeLocalBundleZip = 1,
|
KBSkinSourceModeLocalBundleZip = 1,
|
||||||
|
/// 恢复到默认皮肤(忽略 skinJSON 中的资源字段)
|
||||||
|
KBSkinSourceModeResetToDefault = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// 皮肤下载与应用服务(仅主 App 使用)
|
/// 皮肤下载与应用服务(仅主 App 使用)
|
||||||
@@ -31,7 +33,7 @@ typedef NS_ENUM(NSUInteger, KBSkinSourceMode) {
|
|||||||
///
|
///
|
||||||
/// @param skinJSON 与后端约定的皮肤结构(包含 id/name/background_image/hidden_keys/key_icons 等)
|
/// @param skinJSON 与后端约定的皮肤结构(包含 id/name/background_image/hidden_keys/key_icons 等)
|
||||||
/// @param presenting 用于弹出“键盘权限引导页”的控制器,可为 nil
|
/// @param presenting 用于弹出“键盘权限引导页”的控制器,可为 nil
|
||||||
/// @param mode 资源来源模式:远程 / 本地 bundle
|
/// @param mode 模式:远程 Zip、本地 bundle Zip,或恢复默认皮肤
|
||||||
/// @param completion 应用完成回调(下载/写入全部结束后调用,success 表示是否成功)
|
/// @param completion 应用完成回调(下载/写入全部结束后调用,success 表示是否成功)
|
||||||
- (void)applySkinWithJSON:(NSDictionary *)skinJSON
|
- (void)applySkinWithJSON:(NSDictionary *)skinJSON
|
||||||
fromViewController:(nullable UIViewController *)presenting
|
fromViewController:(nullable UIViewController *)presenting
|
||||||
|
|||||||
@@ -51,6 +51,14 @@
|
|||||||
fromViewController:(UIViewController *)presenting
|
fromViewController:(UIViewController *)presenting
|
||||||
mode:(KBSkinSourceMode)mode
|
mode:(KBSkinSourceMode)mode
|
||||||
completion:(KBSkinApplyCompletion)completion {
|
completion:(KBSkinApplyCompletion)completion {
|
||||||
|
// 模式为“恢复默认皮肤”时,直接调用 KBSkinManager 的 reset 接口,忽略 JSON 内容。
|
||||||
|
if (mode == KBSkinSourceModeResetToDefault) {
|
||||||
|
[[KBSkinManager shared] resetToDefault];
|
||||||
|
if (completion) completion(YES);
|
||||||
|
[KBHUD showInfo:KBLocalized(@"已恢复默认键盘皮肤")];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (skinJSON.count == 0) {
|
if (skinJSON.count == 0) {
|
||||||
if (completion) completion(NO);
|
if (completion) completion(NO);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user