Commit 8afb9f55 cgx

均衡舒压和舒睡新增提示文案

1 个父辈 6666520c
...@@ -107,7 +107,6 @@ ...@@ -107,7 +107,6 @@
_aiWebView.backgroundColor = DSWhite; _aiWebView.backgroundColor = DSWhite;
_aiWebView.UIDelegate = self; _aiWebView.UIDelegate = self;
[_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;
......
//
// NSString+Extras.h
// DreamSleep
//
// Created by peter on 2022/4/15.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSString (Extras)
/**
* @brief 根据字符串属性获取控件高度
* @param text 传入的文本信息
* @param font 字体
* @param maxWidth 最大宽度
* @return height
*/
+ (CGFloat)getHeightWithText:(NSString *)text withFont:(UIFont *)font withMaxWidth:(CGFloat)maxWidth;
@end
NS_ASSUME_NONNULL_END
//
// NSString+Extras.m
// DreamSleep
//
// Created by peter on 2022/4/15.
//
#import "NSString+Extras.h"
@implementation NSString (Extras)
+ (CGFloat)getHeightWithText:(NSString *)text withFont:(UIFont *)font withMaxWidth:(CGFloat)maxWidth
{
NSDictionary *strAttributes = @{NSFontAttributeName:font, NSForegroundColorAttributeName:MainTextColor};
CGSize size = [text boundingRectWithSize:CGSizeMake(maxWidth, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:strAttributes context:nil].size;
return size.height;
}
@end
...@@ -17,6 +17,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -17,6 +17,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (UILabel *)dkLabWithFont:(UIFont *)font; + (UILabel *)dkLabWithFont:(UIFont *)font;
+ (UILabel *)labWithTextColor:(UIColor *)textColor font:(UIFont *)font; + (UILabel *)labWithTextColor:(UIColor *)textColor font:(UIFont *)font;
+ (UILabel *)labWithText:(NSString *)text textColor:(UIColor *)textColor font:(UIFont *)font;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -32,4 +32,12 @@ ...@@ -32,4 +32,12 @@
return lab; return lab;
} }
+ (UILabel *)labWithText:(NSString *)text textColor:(UIColor *)textColor font:(UIFont *)font {
UILabel *lab = [UILabel new];
lab.font = font;
lab.text = text;
lab.textColor = textColor;
return lab;
}
@end @end
...@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
@property CGFloat width; @property CGFloat width;
@property CGFloat x; @property CGFloat x;
@property CGFloat y; @property CGFloat y;
@property CGPoint origin;
/** /**
根据view获取UIViewController(该view必须完成初始化) 根据view获取UIViewController(该view必须完成初始化)
......
...@@ -49,6 +49,10 @@ ...@@ -49,6 +49,10 @@
self.frame = rect; self.frame = rect;
} }
- (CGPoint)origin {
return self.frame.origin;
}
- (UIViewController *)ds_viewController { - (UIViewController *)ds_viewController {
for (UIView* next = [self superview]; next; next = next.superview) { for (UIView* next = [self superview]; next; next = next.superview) {
UIResponder *nextResponder = [next nextResponder]; UIResponder *nextResponder = [next nextResponder];
......
//
// BreathTextView.h
// DreamSleep
//
// Created by peter on 2022/4/15.
//
typedef NS_ENUM(NSInteger, LottieStyle) {
// 均衡呼吸法
LottieStyleBalance,
// 舒睡呼吸法
LottieStyleComfortable
};
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 文本显示区域(新增)
@interface BreathTextView : UIView
- (instancetype)initWithFrame:(CGRect)frame style:(LottieStyle)style;
@end
NS_ASSUME_NONNULL_END
//
// BreathTextView.m
// DreamSleep
//
// Created by peter on 2022/4/15.
//
#import "BreathTextView.h"
@implementation BreathTextView
- (instancetype)initWithFrame:(CGRect)frame style:(LottieStyle)style {
if (self = [super initWithFrame:frame]) {
NSString *text = style == LottieStyleBalance ? @"适用于平复情绪,缓解压力\n\n• 鼻吸气4秒\n\n• 嘴吐气7秒" : @"每天睡前使用2分钟,放松身心快速入睡\n\n• 鼻吸气4秒\n\n• 憋气7秒\n\n• 嘴吐气8秒";
CGFloat height = [NSString getHeightWithText:text withFont:SysFont(14.0) withMaxWidth:self.width];
UILabel *lab = [UILabel labWithText:text textColor:ColorFromHex(0x5A6073) font:SysFont(14.0)];
lab.numberOfLines = 0;
lab.textAlignment = NSTextAlignmentCenter;
lab.frame = CGRectMake(0, 0, self.width, height);
[self addSubview:lab];
self.height = height;
}
return self;
}
@end
...@@ -6,16 +6,10 @@ ...@@ -6,16 +6,10 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "BreathTextView.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, LottieStyle) {
// 均衡呼吸法
LottieStyleBalance,
// 舒睡呼吸法
LottieStyleComfortable
};
///  均衡呼吸法和舒睡4-7-8呼吸法 ///  均衡呼吸法和舒睡4-7-8呼吸法
@interface BreatheController : UIViewController @interface BreatheController : UIViewController
// 动画样式 // 动画样式
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#import <AudioToolbox/AudioToolbox.h> #import <AudioToolbox/AudioToolbox.h>
@interface BreatheController () <UIPickerViewDataSource, UIPickerViewDelegate> @interface BreatheController () <UIPickerViewDataSource, UIPickerViewDelegate>
// 文字显示区
@property (nonatomic, strong) BreathTextView *breathTextView;
// 旋转lottie // 旋转lottie
@property (nonatomic, strong) LOTAnimationView *rotateView; @property (nonatomic, strong) LOTAnimationView *rotateView;
// 缩放lottie // 缩放lottie
...@@ -84,6 +86,7 @@ ...@@ -84,6 +86,7 @@
} }
- (void)initView { - (void)initView {
[self.view addSubview:self.breathTextView];
[self.view addSubview:self.rotateView]; [self.view addSubview:self.rotateView];
[self.view addSubview:self.zoomView]; [self.view addSubview:self.zoomView];
[self.view addSubview:self.minutePickerView]; [self.view addSubview:self.minutePickerView];
...@@ -107,7 +110,7 @@ ...@@ -107,7 +110,7 @@
[self.rotateView mas_makeConstraints:^(MASConstraintMaker *make) { [self.rotateView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.equalTo(@162); make.width.height.equalTo(@162);
make.centerX.equalTo(self.view); make.centerX.equalTo(self.view);
make.topMargin.equalTo(self.view).offset(100); make.topMargin.equalTo(self.breathTextView.mas_bottom).offset(41);
}]; }];
[self.zoomView mas_makeConstraints:^(MASConstraintMaker *make) { [self.zoomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.view); make.center.equalTo(self.view);
...@@ -150,6 +153,7 @@ ...@@ -150,6 +153,7 @@
#pragma mark - Action #pragma mark - Action
- (void)startRelaxAction:(UIButton *)sender { - (void)startRelaxAction:(UIButton *)sender {
sender.selected = !sender.selected; sender.selected = !sender.selected;
self.breathTextView.hidden = YES;
self.rotateView.hidden = YES; self.rotateView.hidden = YES;
self.timeLb.hidden = YES; self.timeLb.hidden = YES;
self.minuteLb.hidden = YES; self.minuteLb.hidden = YES;
...@@ -257,6 +261,13 @@ ...@@ -257,6 +261,13 @@
return attributedString; return attributedString;
} }
- (BreathTextView *)breathTextView {
if (!_breathTextView) {
_breathTextView = [[BreathTextView alloc] initWithFrame:CGRectMake(0, kTopHeight(0) + 61, kScreenWidth, 100) style:self.style];
}
return _breathTextView;
}
- (LOTAnimationView *)rotateView { - (LOTAnimationView *)rotateView {
if(!_rotateView) { if(!_rotateView) {
_rotateView = [LOTAnimationView animationNamed:self.rotateLottieFile]; _rotateView = [LOTAnimationView animationNamed:self.rotateLottieFile];
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#import "UIView+Extras.h" #import "UIView+Extras.h"
#import "UILabel+Extras.h" #import "UILabel+Extras.h"
#import "UIButton+Extras.h" #import "UIButton+Extras.h"
#import "NSString+Extras.h"
#import "NaviBarHandlerProtocol.h" #import "NaviBarHandlerProtocol.h"
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!