YOUPAILZBigCastAudioSetVC.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. //
  2. // YOUPAILZBigCastAudioSetVC.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/7/9.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZBigCastAudioSetVC.h"
  9. #import "YOUPAILZBigCastSoundRecordView.h"
  10. #import <CoreText/CoreText.h>
  11. @interface YOUPAILZBigCastAudioSetVC ()
  12. @property (nonatomic, strong) NSArray *youpaipdataSource;
  13. @property (nonatomic, weak) UILabel *youpaiptipsL;
  14. @property (nonatomic, assign) NSInteger youpaipindex;
  15. @end
  16. @implementation YOUPAILZBigCastAudioSetVC
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.title = @"声音展示";
  20. self.view.backgroundColor = [UIColor whiteColor];
  21. [self requestVoiceList];
  22. [self youpaifinitUI];
  23. }
  24. - (void)youpaifinitUI{
  25. UILabel *descL = [[UILabel alloc] init];
  26. descL.text = @"展示你的声线,更有吸引力~";
  27. descL.font = LCFont12;
  28. descL.textColor = LZA3AABEColor;
  29. [self.view addSubview:descL];
  30. [descL mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.left.offset(14.0f);
  32. make.top.offset(25.0f + NavBarHeight);
  33. make.right.offset(-14.0f);
  34. }];
  35. UIView *tipsBgV = [[UIView alloc] init];
  36. tipsBgV.backgroundColor = LZF7F8FAColor;
  37. tipsBgV.layer.cornerRadius = 6.0f;
  38. tipsBgV.clipsToBounds = YES;
  39. [self.view addSubview:tipsBgV];
  40. [tipsBgV mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.offset(14.0f);
  42. make.right.offset(-14.0f);
  43. make.top.equalTo(descL.mas_bottom).offset(10.0f);
  44. }];
  45. UIButton *otherWordsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  46. otherWordsBtn.layer.borderColor = LZ7C69FEColor.CGColor;
  47. otherWordsBtn.layer.borderWidth = 1.0f;
  48. // otherWordsBtn.backgroundColor = HexColorFromRGB(0x4F4B5B);
  49. otherWordsBtn.layer.cornerRadius = 13.5f;
  50. otherWordsBtn.clipsToBounds = YES;
  51. otherWordsBtn.titleLabel.font = LCFont12;
  52. [otherWordsBtn setTitleColor:LZ7C69FEColor forState:UIControlStateNormal];
  53. [otherWordsBtn setTitle:@"换一句" forState:UIControlStateNormal];
  54. [otherWordsBtn addTarget:self action:@selector(otherWordsBtnClick) forControlEvents:UIControlEventTouchUpInside];
  55. [tipsBgV addSubview:otherWordsBtn];
  56. [otherWordsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.centerX.equalTo(tipsBgV.mas_centerX);
  58. make.bottom.offset(-25.0f);
  59. make.size.mas_offset(CGSizeMake(76.0f, 27.0f));
  60. }];
  61. UILabel *tipsL = [[UILabel alloc] init];
  62. // tipsL.text = @"说一段话介绍自己,或唱一首歌!";
  63. tipsL.font = LCFont14;
  64. tipsL.textColor = LZ273145Color;
  65. tipsL.textAlignment = NSTextAlignmentCenter;
  66. tipsL.numberOfLines = 0;
  67. [tipsBgV addSubview:tipsL];
  68. self.youpaiptipsL = tipsL;
  69. [tipsL mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.offset(12.0f);
  71. make.top.offset(25.0f);
  72. make.right.offset(-12.0f);
  73. make.bottom.equalTo(otherWordsBtn.mas_top).offset(-20.0f);
  74. }];
  75. YOUPAILZBigCastSoundRecordView *soundRecordView = [[YOUPAILZBigCastSoundRecordView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, KScreenWidth, 195.0f)];
  76. soundRecordView.youpaipminTimer = 5;
  77. soundRecordView.youpaipmaxTimer = 60;
  78. /// 音频录制完成
  79. @weakify(self);
  80. [soundRecordView setSoundRecordFinishBlock:^(NSURL * _Nonnull fileURL, NSInteger duration) {
  81. [ZCHUDHelper showWithStatus:@"上传中..."];
  82. [LCCommonHttp uploadWithAudioPath:fileURL.resourceSpecifier Type:@"mp3" successBlock:^(NSString *ossFilePath) {
  83. @strongify(self);
  84. if (ossFilePath.length != 0) {
  85. // NSDictionary *params = @{
  86. // @"mp3":ossFilePath,
  87. // @"mp3_second":@(duration)
  88. // };
  89. [ZCHUDHelper dismiss];
  90. if (self.successBlock) {
  91. self.successBlock(ossFilePath, duration);
  92. [self.navigationController popViewControllerAnimated:YES];
  93. }
  94. // [LCHttpHelper requestWithURLString:UserVoice parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
  95. // [ZCHUDHelper dismiss];
  96. // NSDictionary* dict = (NSDictionary*)responseObject;
  97. // NSInteger code = [[dict objectForKey:@"code"] integerValue];
  98. // if (code==0) {
  99. // [weakSelf.navigationController popViewControllerAnimated:YES];
  100. // if ([[NSFileManager defaultManager] fileExistsAtPath:fileURL.resourceSpecifier]){
  101. // [[NSFileManager defaultManager] removeItemAtPath:fileURL.resourceSpecifier error:nil];
  102. // }
  103. // }else{
  104. // [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
  105. // }
  106. // } failure:^(NSError *error) {
  107. // [ZCHUDHelper showTitle:error.localizedDescription];
  108. //
  109. // }];
  110. }
  111. }];
  112. }];
  113. [self.view addSubview:soundRecordView];
  114. [soundRecordView mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.left.offset(0.0f);
  116. make.right.offset(0.0f);
  117. make.height.offset(195.0f);
  118. make.bottom.offset(-44.0f-SafeHeight);
  119. }];
  120. }
  121. - (void)otherWordsBtnClick{
  122. self.youpaipindex ++;
  123. if (self.youpaipdataSource.count < self.youpaipindex) {
  124. [self setTipsLAttrStr];
  125. }else{
  126. [self requestVoiceList];
  127. }
  128. }
  129. - (void)requestVoiceList{
  130. WeakSelf;
  131. [LCHttpHelper requestWithURLString:VoiceList parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  132. NSDictionary* dict = (NSDictionary*)responseObject;
  133. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  134. if (code == 0) {
  135. weakSelf.youpaipdataSource = [[dict objectForKey:@"data"] objectForKey:@"list"];
  136. if (weakSelf.youpaipdataSource.count != 0) {
  137. weakSelf.youpaipindex = 0;
  138. [weakSelf setTipsLAttrStr];
  139. }
  140. }
  141. } failure:^(NSError *error) {
  142. }];
  143. }
  144. - (void)setTipsLAttrStr{
  145. NSString *content = nil;
  146. if (self.youpaipdataSource.count > self.youpaipindex) {
  147. content = self.youpaipdataSource[self.youpaipindex];
  148. }
  149. NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:content];
  150. NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
  151. paragraphStyle1.alignment=NSTextAlignmentJustified;
  152. NSDictionary * dic =@{
  153. NSParagraphStyleAttributeName:paragraphStyle1,
  154. NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone],
  155. };
  156. [attributedString1 setAttributes:dic range:NSMakeRange(0, attributedString1.length)];
  157. [self.youpaiptipsL setAttributedText:attributedString1];
  158. NSInteger lineCount = [self rowsOfString:content withFont:LCFont14 withWidth:KScreenWidth - 52.0f];
  159. if (lineCount > 1) {
  160. self.youpaiptipsL.textAlignment = NSTextAlignmentLeft;
  161. }else{
  162. self.youpaiptipsL.textAlignment = NSTextAlignmentCenter;
  163. }
  164. }
  165. -(CGFloat)rowsOfString:(NSString *)text withFont:(UIFont *)font withWidth:(CGFloat)width{
  166. if (!text || text.length == 0) {
  167. return 0;
  168. }
  169. CTFontRef myFont = CTFontCreateWithName(( CFStringRef)([font fontName]), [font pointSize], NULL);
  170. NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
  171. [attStr addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)myFont range:NSMakeRange(0, attStr.length)];
  172. CFRelease(myFont);
  173. CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString(( CFAttributedStringRef)attStr);
  174. CGMutablePathRef path = CGPathCreateMutable();
  175. CGPathAddRect(path, NULL, CGRectMake(0,0,width,MAXFLOAT));
  176. CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, NULL);
  177. NSArray *lines = ( NSArray *)CTFrameGetLines(frame);
  178. return [@(lines.count) floatValue];
  179. }
  180. @end