Commit 8762676d cgx

AI睡眠教练添加遮罩

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