Commit 8762676d cgx

AI睡眠教练添加遮罩

1 个父辈 56e45afb
......@@ -44,6 +44,11 @@ NS_ASSUME_NONNULL_BEGIN
// 添加遮罩
- (void)addMaskWithType:(MaskType)type cornerRadius:(CGFloat)cornerRadius;
// 添加遮罩
- (void)addMask;
// 移除遮罩
- (void)removeMask;
- (void)setCornerRadiusRect:(UIRectCorner)rectCorner cornerRadius:(CGFloat)cornerRadius;
@end
NS_ASSUME_NONNULL_END
......@@ -131,6 +131,31 @@
maskView.layer.mask = maskLayer;
}
- (void)addMask {
[self removeMask];
UIView *maskView = [[UIView alloc] initWithFrame:self.bounds];
maskView.backgroundColor = ColorFromHex(0x6B7485);
maskView.alpha = .5;
maskView.tag = 999;
maskView.userInteractionEnabled = NO;
[self addSubview:maskView];
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:maskView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(0, 0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = maskView.bounds;
maskLayer.path = path.CGPath;
maskView.layer.mask = maskLayer;
}
- (void)removeMask {
for (UIView *maskView in self.subviews) {
if (maskView.tag == 999) {
[maskView removeFromSuperview];
}
}
}
- (void)setCornerRadiusRect:(UIRectCorner)rectCorner cornerRadius:(CGFloat)cornerRadius {
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:rectCorner cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
......
......@@ -44,6 +44,8 @@ FOUNDATION_EXTERN NSString * const NoisePlaylistHasChange;
FOUNDATION_EXTERN NSString * const NoiseTimingDidClick;
// Unity
FOUNDATION_EXTERN NSString * const ExitCoaxSleep;
// 刷新AI睡眠教练通知
FOUNDATION_EXTERN NSString * const NeedUpdateAICoach;
// 用户基础信息
FOUNDATION_EXTERN NSString * const UserBasicInfo;
......
......@@ -30,6 +30,7 @@ NSString * const NeedUpdateHomePage = @"NeedUpdateHomePageNoti";
NSString * const NoisePlaylistHasChange = @"NoisePlaylistHasChangeNoti";
NSString * const NoiseTimingDidClick = @"NoiseTimingDidClickNoti";
NSString * const ExitCoaxSleep = @"ExitCoaxSleepNoti";
NSString * const NeedUpdateAICoach = @"NeedUpdateAICoachNoti";
NSString * const UserBasicInfo = @"UserBasicInfo";
......
......@@ -11,7 +11,8 @@
@interface AISleepCoachController () <WKNavigationDelegate, WKScriptMessageHandler, WKUIDelegate>
@property (strong, nonatomic) WKWebView *aiWebView;
@property (nonatomic, strong) UIProgressView *progressView;
@property (strong, nonatomic) NSURLRequest *request;
@property (strong, nonatomic) UIProgressView *progressView;
@end
@implementation AISleepCoachController
......@@ -22,10 +23,37 @@
// 创建WKWebView对象,添加到界面(storyboard没有控件)
[self.view addSubview:self.aiWebView];
[self.view addSubview:self.progressView];
// 监听AI睡眠教练页面需要刷新数据通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needUpdateAiCoach) name:NeedUpdateAICoach object:nil];
}
- (void)dealloc {
[self.aiWebView removeObserver:self forKeyPath:@"estimatedProgress"];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NeedUpdateAICoach object:nil];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// 夜间模式
if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
[self.aiWebView addMask];
} else {
[self.aiWebView removeMask];
}
}
#pragma mark - js和oc交互
- (void)startOpen {
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
}
}
#pragma mark - 登录成功后刷新
- (void)needUpdateAiCoach {
[self.aiWebView loadRequest:self.request];
}
#pragma mark - WKWebView的监听方法
......@@ -57,7 +85,7 @@
//iOS端 wkwebview代理方法
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
if ([navigationAction.request.URL.absoluteString isEqualToString:@"xc://scan"]) {
if ([navigationAction.request.URL.absoluteString isEqualToString:@"xc://scan"]) {
//调用原生扫描二维码
decisionHandler(WKNavigationActionPolicyCancel);
return;
......@@ -69,8 +97,8 @@
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message {
if ([message.name isEqualToString:@"click"]) {
// NSDictionary *jsData = message.body;
// NSLog(@"%@", message.name);
// NSDictionary *jsData = message.body;
// NSLog(@"%@", message.name);
//读取js function的字符串
// NSString *jsFunctionString = jsData[@"result"];
// //拼接调用该方法的js字符串(convertDictionaryToJson:方法将NSDictionary转成JSON格式的字符串)
......@@ -87,37 +115,32 @@
- (WKWebView *)aiWebView {
if (!_aiWebView) {
// _aiWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTabBarHeight)];
// _aiWebView.backgroundColor = DSWhite;
// 进行配置控制器
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
// 实例化对象
configuration.userContentController = [WKUserContentController new];
// 调用JS方法
[configuration.userContentController addScriptMessageHandler:self name:@"click"];
[configuration.userContentController addScriptMessageHandler:self name:@"Android.jump2Native(2, 0)"];
// 进行偏好设置
WKPreferences *preferences = [WKPreferences new];
preferences.javaScriptCanOpenWindowsAutomatically = YES;
preferences.javaScriptEnabled = YES;
configuration.preferences = preferences;
// 初始化WKWebView
_aiWebView = [[WKWebView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTabBarHeight) configuration:configuration];
_aiWebView.backgroundColor = DSWhite;
_aiWebView.UIDelegate = self;
_aiWebView.scrollView.bounces = NO;
[_aiWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
_aiWebView.navigationDelegate = self;
_aiWebView.scrollView.showsVerticalScrollIndicator = NO;
_aiWebView.scrollView.showsHorizontalScrollIndicator = NO;
// 解决页面顶部出现白色问题
_aiWebView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
// 测试地址:https://www.cbti.cn/sleep/ai/sleep_aicocah
NSURL *url = [NSURL URLWithString:@"https://cbti.mynatapp.cc/sleep/ai/sleep_aicocah"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_aiWebView loadRequest:request];
self.request = [NSURLRequest requestWithURL:[NSURL URLWithString:AICoachURL]];
[_aiWebView loadRequest:self.request];
}
return _aiWebView;
}
......
......@@ -57,6 +57,8 @@
// 刷新主页数据
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateHomePage object:nil];
// 刷新AI睡眠教练
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateAICoach object:nil];
}
}];
}
......
......@@ -50,6 +50,8 @@
[self dismissViewControllerAnimated:YES completion:nil];
// 刷新主页数据
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateHomePage object:nil];
// 刷新AI睡眠教练
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateAICoach object:nil];
} else {
[DSProgressHUD showToast:requestModel.errorInfo];
}
......@@ -129,6 +131,8 @@
[self dismissViewControllerAnimated:YES completion:nil];
// 刷新主页数据
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateHomePage object:nil];
// 刷新AI睡眠教练
[[NSNotificationCenter defaultCenter] postNotificationName:NeedUpdateAICoach object:nil];
} else {
[DSProgressHUD showToast:requestModel.errorInfo];
}
......@@ -175,7 +179,7 @@
#pragma mark - ASAuthorizationControllerPresentationContextProviding
#pragma mark - 告诉代理应该在哪个window 展示内容给用户
- (ASPresentationAnchor)presentationAnchorForAuthorizationController:(ASAuthorizationController *)controller API_AVAILABLE(ios(13.0)){
NSLog(@"调用展示window方法:%s", __FUNCTION__);
DSLog(@"调用展示window方法:%s", __FUNCTION__);
// 返回window
return self.view.window;
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!