118 lines
3.7 KiB
Objective-C
118 lines
3.7 KiB
Objective-C
//
|
||
// HomeMainVC.m
|
||
// keyBoard
|
||
//
|
||
// Created by Mac on 2025/11/6.
|
||
//
|
||
|
||
#import "HomeMainVC.h"
|
||
#import "HomeHeadView.h"
|
||
#import "KBPanModalView.h"
|
||
#import "KBGuideVC.h" // 首次安装指引页
|
||
#import "WMDragView.h"
|
||
|
||
@interface HomeMainVC ()
|
||
@property (nonatomic, strong) HomeHeadView *headView;
|
||
@property (nonatomic, strong) KBPanModalView *simplePanModalView;
|
||
|
||
/// 权限按钮
|
||
@property (nonatomic, strong) WMDragView *keyPermissButton;
|
||
@end
|
||
|
||
@implementation HomeMainVC
|
||
|
||
- (void)viewDidLoad {
|
||
[super viewDidLoad];
|
||
|
||
UIImageView *bgImageView = [[UIImageView alloc] init];
|
||
bgImageView.image = [UIImage imageNamed:@"home_bg_image"];
|
||
[self.view addSubview:bgImageView];
|
||
[bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.edges.equalTo(self.view);
|
||
}];
|
||
[self.view addSubview:self.headView];
|
||
[self setupMas];
|
||
// 创建sheetVC
|
||
self.simplePanModalView = [[KBPanModalView alloc] init];
|
||
// 使用宏,避免误写成函数指针判断导致恒为 true
|
||
if (KB_DEVICE_HAS_NOTCH) {
|
||
self.simplePanModalView.minHeight = 473 - 44 + KB_NAV_TOTAL_HEIGHT;
|
||
}else{
|
||
self.simplePanModalView.minHeight = 473 - 44 + KB_NAV_TOTAL_HEIGHT;
|
||
//
|
||
}
|
||
self.simplePanModalView.topInset = 100;
|
||
[self.simplePanModalView presentInView:self.view];
|
||
[self.view addSubview:self.keyPermissButton];
|
||
self.keyPermissButton.frame = CGRectMake(KB_SCREEN_WIDTH - 92, KB_SCREEN_HEIGHT - 78 - 120, 92, 78);
|
||
|
||
KBWeakSelf
|
||
self.keyPermissButton.clickDragViewBlock = ^(WMDragView *dragView){
|
||
KBGuideVC *vc = [KBGuideVC new];
|
||
[weakSelf.navigationController pushViewController:vc animated:true];
|
||
};
|
||
|
||
/// 测试groups
|
||
// NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:AppGroup];
|
||
// // 写入一个简单字符串
|
||
// [sharedDefaults setObject:@"Hello From Main App" forKey:@"TestSharedString"];
|
||
// [sharedDefaults synchronize];
|
||
// NSLog(@"[MainApp] 写入完成");
|
||
}
|
||
|
||
// 在界面可见后做“首次安装”检查,避免在 viewDidLoad 期间 push 引起的转场警告
|
||
- (void)viewDidAppear:(BOOL)animated {
|
||
[super viewDidAppear:animated];
|
||
[self kb_showGuideIfFirstLaunch];
|
||
}
|
||
|
||
/// 首次安装进入首页时,跳转到 KBGuideVC
|
||
- (void)kb_showGuideIfFirstLaunch {
|
||
static NSString *const kKBHasLaunchedOnce = @"KBHasLaunchedOnce";
|
||
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
|
||
if (![ud boolForKey:kKBHasLaunchedOnce]) {
|
||
[ud setBool:YES forKey:kKBHasLaunchedOnce];
|
||
[ud synchronize];
|
||
|
||
// 避免重复 push;同时确保在主线程执行
|
||
if (self.navigationController && self.presentedViewController == nil) {
|
||
KBGuideVC *vc = [KBGuideVC new];
|
||
vc.hidesBottomBarWhenPushed = YES;
|
||
dispatch_async(dispatch_get_main_queue(), ^{
|
||
[self.navigationController pushViewController:vc animated:YES];
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
- (void)setupMas{
|
||
[self.headView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||
make.left.right.equalTo(self.view);
|
||
make.top.equalTo(self.view).offset(KB_NAV_TOTAL_HEIGHT);
|
||
make.height.mas_equalTo(473 - 44);
|
||
}];
|
||
}
|
||
|
||
|
||
#pragma mark - lazy
|
||
- (HomeHeadView *)headView{
|
||
if (!_headView) {
|
||
_headView = [[HomeHeadView alloc] init];
|
||
}
|
||
return _headView;
|
||
}
|
||
|
||
|
||
- (WMDragView *)keyPermissButton{
|
||
if (!_keyPermissButton) {
|
||
_keyPermissButton = [[WMDragView alloc] init];
|
||
_keyPermissButton.backgroundColor = [UIColor clearColor];
|
||
_keyPermissButton.isKeepBounds = true;
|
||
[_keyPermissButton.button setImage:[UIImage imageNamed:@"key_permiss_icon"] forState:UIControlStateNormal];
|
||
|
||
}
|
||
return _keyPermissButton;
|
||
}
|
||
|
||
@end
|