123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- //
- // YOUPAILZBigCastAudioSetVC.m
- // VQU
- //
- // Created by CY on 2021/7/9.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZBigCastAudioSetVC.h"
- #import "YOUPAILZBigCastSoundRecordView.h"
- #import <CoreText/CoreText.h>
- @interface YOUPAILZBigCastAudioSetVC ()
- @property (nonatomic, strong) NSArray *youpaipdataSource;
- @property (nonatomic, weak) UILabel *youpaiptipsL;
- @property (nonatomic, assign) NSInteger youpaipindex;
- @end
- @implementation YOUPAILZBigCastAudioSetVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"声音展示";
- self.view.backgroundColor = [UIColor whiteColor];
- [self requestVoiceList];
- [self youpaifinitUI];
- }
- - (void)youpaifinitUI{
- UILabel *descL = [[UILabel alloc] init];
- descL.text = @"展示你的声线,更有吸引力~";
- descL.font = LCFont12;
- descL.textColor = LZA3AABEColor;
- [self.view addSubview:descL];
- [descL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(14.0f);
- make.top.offset(25.0f + NavBarHeight);
- make.right.offset(-14.0f);
- }];
-
- UIView *tipsBgV = [[UIView alloc] init];
- tipsBgV.backgroundColor = LZF7F8FAColor;
- tipsBgV.layer.cornerRadius = 6.0f;
- tipsBgV.clipsToBounds = YES;
- [self.view addSubview:tipsBgV];
- [tipsBgV mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(14.0f);
- make.right.offset(-14.0f);
- make.top.equalTo(descL.mas_bottom).offset(10.0f);
- }];
-
- UIButton *otherWordsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- otherWordsBtn.layer.borderColor = LZ7C69FEColor.CGColor;
- otherWordsBtn.layer.borderWidth = 1.0f;
- // otherWordsBtn.backgroundColor = HexColorFromRGB(0x4F4B5B);
- otherWordsBtn.layer.cornerRadius = 13.5f;
- otherWordsBtn.clipsToBounds = YES;
- otherWordsBtn.titleLabel.font = LCFont12;
- [otherWordsBtn setTitleColor:LZ7C69FEColor forState:UIControlStateNormal];
- [otherWordsBtn setTitle:@"换一句" forState:UIControlStateNormal];
- [otherWordsBtn addTarget:self action:@selector(otherWordsBtnClick) forControlEvents:UIControlEventTouchUpInside];
- [tipsBgV addSubview:otherWordsBtn];
- [otherWordsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(tipsBgV.mas_centerX);
- make.bottom.offset(-25.0f);
- make.size.mas_offset(CGSizeMake(76.0f, 27.0f));
- }];
-
- UILabel *tipsL = [[UILabel alloc] init];
- // tipsL.text = @"说一段话介绍自己,或唱一首歌!";
- tipsL.font = LCFont14;
- tipsL.textColor = LZ273145Color;
- tipsL.textAlignment = NSTextAlignmentCenter;
- tipsL.numberOfLines = 0;
- [tipsBgV addSubview:tipsL];
- self.youpaiptipsL = tipsL;
- [tipsL mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(12.0f);
- make.top.offset(25.0f);
- make.right.offset(-12.0f);
- make.bottom.equalTo(otherWordsBtn.mas_top).offset(-20.0f);
- }];
-
- YOUPAILZBigCastSoundRecordView *soundRecordView = [[YOUPAILZBigCastSoundRecordView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, KScreenWidth, 195.0f)];
- soundRecordView.youpaipminTimer = 5;
- soundRecordView.youpaipmaxTimer = 60;
- /// 音频录制完成
- @weakify(self);
- [soundRecordView setSoundRecordFinishBlock:^(NSURL * _Nonnull fileURL, NSInteger duration) {
- [ZCHUDHelper showWithStatus:@"上传中..."];
- [LCCommonHttp uploadWithAudioPath:fileURL.resourceSpecifier Type:@"mp3" successBlock:^(NSString *ossFilePath) {
- @strongify(self);
- if (ossFilePath.length != 0) {
- // NSDictionary *params = @{
- // @"mp3":ossFilePath,
- // @"mp3_second":@(duration)
- // };
- [ZCHUDHelper dismiss];
- if (self.successBlock) {
- self.successBlock(ossFilePath, duration);
- [self.navigationController popViewControllerAnimated:YES];
- }
- // [LCHttpHelper requestWithURLString:UserVoice parameters:params needToken:YES type:HttpRequestTypePost success:^(id responseObject) {
- // [ZCHUDHelper dismiss];
- // NSDictionary* dict = (NSDictionary*)responseObject;
- // NSInteger code = [[dict objectForKey:@"code"] integerValue];
- // if (code==0) {
- // [weakSelf.navigationController popViewControllerAnimated:YES];
- // if ([[NSFileManager defaultManager] fileExistsAtPath:fileURL.resourceSpecifier]){
- // [[NSFileManager defaultManager] removeItemAtPath:fileURL.resourceSpecifier error:nil];
- // }
- // }else{
- // [ZCHUDHelper showTitle:[dict objectForKey:@"message"]];
- // }
- // } failure:^(NSError *error) {
- // [ZCHUDHelper showTitle:error.localizedDescription];
- //
- // }];
- }
- }];
- }];
- [self.view addSubview:soundRecordView];
- [soundRecordView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.offset(0.0f);
- make.right.offset(0.0f);
- make.height.offset(195.0f);
- make.bottom.offset(-44.0f-SafeHeight);
- }];
- }
- - (void)otherWordsBtnClick{
- self.youpaipindex ++;
- if (self.youpaipdataSource.count < self.youpaipindex) {
- [self setTipsLAttrStr];
- }else{
- [self requestVoiceList];
- }
- }
- - (void)requestVoiceList{
- WeakSelf;
- [LCHttpHelper requestWithURLString:VoiceList parameters:@{} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {
- weakSelf.youpaipdataSource = [[dict objectForKey:@"data"] objectForKey:@"list"];
- if (weakSelf.youpaipdataSource.count != 0) {
- weakSelf.youpaipindex = 0;
- [weakSelf setTipsLAttrStr];
- }
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)setTipsLAttrStr{
- NSString *content = nil;
- if (self.youpaipdataSource.count > self.youpaipindex) {
- content = self.youpaipdataSource[self.youpaipindex];
- }
- NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:content];
- NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
- paragraphStyle1.alignment=NSTextAlignmentJustified;
- NSDictionary * dic =@{
- NSParagraphStyleAttributeName:paragraphStyle1,
- NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleNone],
- };
- [attributedString1 setAttributes:dic range:NSMakeRange(0, attributedString1.length)];
- [self.youpaiptipsL setAttributedText:attributedString1];
- NSInteger lineCount = [self rowsOfString:content withFont:LCFont14 withWidth:KScreenWidth - 52.0f];
- if (lineCount > 1) {
- self.youpaiptipsL.textAlignment = NSTextAlignmentLeft;
- }else{
- self.youpaiptipsL.textAlignment = NSTextAlignmentCenter;
- }
- }
- -(CGFloat)rowsOfString:(NSString *)text withFont:(UIFont *)font withWidth:(CGFloat)width{
- if (!text || text.length == 0) {
- return 0;
- }
- CTFontRef myFont = CTFontCreateWithName(( CFStringRef)([font fontName]), [font pointSize], NULL);
- NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
- [attStr addAttribute:(NSString *)kCTFontAttributeName value:(__bridge id)myFont range:NSMakeRange(0, attStr.length)];
- CFRelease(myFont);
- CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString(( CFAttributedStringRef)attStr);
- CGMutablePathRef path = CGPathCreateMutable();
- CGPathAddRect(path, NULL, CGRectMake(0,0,width,MAXFLOAT));
- CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, NULL);
- NSArray *lines = ( NSArray *)CTFrameGetLines(frame);
- return [@(lines.count) floatValue];
- }
- @end
|