ReleaseDynamicVC.m 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465
  1. //
  2. // ReleaseDynamicVC.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/11/26.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "ReleaseDynamicVC.h"
  9. #import "UITextView+ZWPlaceHolder.h"
  10. #import "ChatEmojiView.h"
  11. #import "EmojiObj.h"
  12. #import "ChatBottomBarView.h"
  13. #import "ReleaseAtPeopleVC.h"
  14. #import "ReleaseTopicVC.h"
  15. #import <CoreLocation/CoreLocation.h>
  16. #import "PersonCenterUserModel.h"
  17. #import "MGDynamicTopicModel.h"
  18. #import "BzoneLogic.h"
  19. #import "UIView+CWChat.h"
  20. #import "CWRecordModel.h"
  21. #import "HJAudioBubble.h"
  22. #import <ZQPlayer/ZQPlayer.h>
  23. #import <AVFoundation/AVFoundation.h>
  24. #import "JZVideoPlayerView.h"
  25. #import "MultipleFileUploads.h"
  26. #define kATFormat @"@%@ "
  27. #define kATRegular @"@[\\u4e00-\\u9fa5\\w\\-\\_]+ "
  28. typedef NS_ENUM(NSInteger, BGMediaType)
  29. {
  30. BGMediaTypeText =1, /**<1文本*/
  31. BGMediaTypeImage, /**<2图片*/
  32. BGMediaTypeVideo, /**<3视频*/
  33. };
  34. @interface ReleaseDynamicVC ()<UITextViewDelegate,JZPlayerViewDelegate>{
  35. JZVideoPlayerView *_jzPlayer;
  36. }
  37. @property(nonatomic,strong) UIButton *closeBtn;
  38. @property(nonatomic,strong) UIButton *releaseeBtn;
  39. @property(nonatomic, strong) UIScrollView *mainScrollView;
  40. //备注
  41. @property(nonatomic,strong) UITextView *titleTextView;/**<标题*/
  42. @property(nonatomic,strong) UIView *centerView;/**<*/
  43. @property(nonatomic,strong) ChatBarTextView *noteTextView;/**<文字*/
  44. @property(nonatomic,strong) UIView *topicView;/**<话题*/
  45. @property(nonatomic,strong) UIView *locationView;/**<定位*/
  46. @property(nonatomic, strong) UILabel *contentNumL;
  47. @property(nonatomic,strong) UIButton *locationBtn;/**<定位*/
  48. @property(nonatomic, strong) NSString *city;
  49. @property(nonatomic,strong) UIView *anonymousView;/**<匿名*/
  50. @property(nonatomic, assign) BOOL showLocation;
  51. @property(nonatomic, assign) BOOL hidName;
  52. @property(nonatomic,strong) UIView *toolView;/**<工具*/
  53. @property(nonatomic,strong) UIButton *topicBtn;/**<话题*/
  54. @property(nonatomic,strong) UIButton *topicTipBtn;/**<话题Tip*/
  55. @property(nonatomic,strong) UIButton *imageBtn;
  56. @property(nonatomic, strong) UIButton *videoBtn;
  57. @property(nonatomic,strong) UIButton *emojBtn;
  58. @property(nonatomic, strong) UIButton *atBtn;
  59. @property(nonatomic, assign) BOOL video;
  60. //发布按钮
  61. @property(nonatomic,strong) UIButton *submitBtn;
  62. @property(nonatomic, strong) UIButton *delAudio;
  63. @property (strong, nonatomic) ChatEmojiView *emojiView;
  64. @property (assign, nonatomic) CGSize keyboardSize;
  65. @property (assign, nonatomic) CGFloat oldTextViewHeight;
  66. @property (assign, nonatomic) CGFloat animationDuration;
  67. @property (nonatomic, assign, getter=isClosed) BOOL close;
  68. @property (nonatomic, assign) FWChatBarShowType showType;
  69. @property(nonatomic, strong) CLLocationManager *locationManager;
  70. @property(nonatomic, strong) NSString *selectedTopicID;
  71. @property(nonatomic, assign) NSInteger videoDurationTime;/**<限制-最大视频时长(秒)*/
  72. @property(nonatomic, assign) NSInteger selectedVideoDurationTime;/**<视频时长(秒)*/
  73. @property(nonatomic, assign) NSInteger textMaxlength;/**<限制-动态文本长度*/
  74. @property(nonatomic, assign) NSInteger imgMaxCount;/**<限制-图片个数*/
  75. @property(nonatomic, assign) BGMediaType type;
  76. @property(nonatomic, strong) BzoneLogic *bzoneLogic;
  77. /** 音频气泡 */
  78. @property(nonatomic,strong) AVPlayer *player;
  79. @property(nonatomic, strong) MultipleFileUploads *multipleFileUploads;
  80. @property(nonatomic, strong) UIButton *addImgBtn;
  81. @end
  82. @implementation ReleaseDynamicVC
  83. - (void)viewDidLoad {
  84. [super viewDidLoad];
  85. UIImageView *topImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, SCREEN_HEIGHT)];
  86. topImgView.image = [UIImage imageNamed:@"mainBg"];
  87. [self.view addSubview:topImgView];
  88. [self initNavView];
  89. _bzoneLogic = [BzoneLogic new];
  90. self.selectedTopicID = @"";
  91. self.type = BGMediaTypeText;
  92. [self requestLimit];
  93. [self initViews];
  94. self.showInView = self.mainScrollView;
  95. [self initTopic];
  96. [self initPickerView];
  97. self.pickerCollectionView.hidden = YES;
  98. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  99. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  100. [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:kBlackColor,
  101. NSFontAttributeName:[UIFont systemFontOfSize:15]
  102. } forState:UIControlStateNormal];
  103. }
  104. #pragma mark - Private Methods
  105. - (void)keyboardWillHide:(NSNotification *)notification
  106. {
  107. if (self.isClosed)
  108. {
  109. return;
  110. }
  111. self.keyboardSize = CGSizeZero;
  112. if (_showType == FWChatBarShowTypeKeyboard)
  113. {
  114. _showType = FWChatBarShowTypeNothing;
  115. }
  116. [self updateChatBarKeyBoardConstraints];
  117. // [self updateChatBarConstraintsIfNeeded];
  118. }
  119. - (void)keyboardWillShow:(NSNotification *)notification
  120. {
  121. if (self.isClosed)
  122. {
  123. return;
  124. }
  125. CGFloat oldHeight = self.keyboardSize.height;
  126. self.keyboardSize = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
  127. //兼容搜狗输入法:一次键盘事件会通知两次,且键盘高度不一。
  128. if (self.keyboardSize.height != oldHeight)
  129. {
  130. _showType = FWChatBarShowTypeNothing;
  131. }
  132. if (self.keyboardSize.height == 0)
  133. {
  134. _showType = FWChatBarShowTypeNothing;
  135. return;
  136. }
  137. // 获取键盘弹出动画时间
  138. _animationDuration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
  139. // self.allowTextViewContentOffset = YES;
  140. [self updateChatBarKeyBoardConstraints];
  141. self.showType = FWChatBarShowTypeKeyboard;
  142. }
  143. - (void)updateChatBarKeyBoardConstraints
  144. {
  145. self.toolView.y = kScreenH -(self.keyboardSize.height + MG_BOTTOM_MARGIN + 50);
  146. }
  147. - (void)requestLimit{
  148. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  149. [parmDict setObject:@"dynamic" forKey:@"ctl"];
  150. [parmDict setObject:@"dynamic_rule" forKey:@"act"];
  151. FWWeakify(self)
  152. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  153. NSArray * array = responseJson[@"data"];
  154. for (NSDictionary * dict in array) {
  155. NSString * name = dict[@"name"];
  156. if ([name isEqualToString:@"dynaic_video_length"]) {
  157. self.videoDurationTime = [dict[@"value"] integerValue];
  158. }
  159. if ([name isEqualToString:@"dynaic_txt_length"]) {
  160. self.textMaxlength = [dict[@"value"] integerValue];
  161. self.contentNumL.text = [NSString stringWithFormat:@"0/%ld",self.textMaxlength];
  162. self.noteTextView.zw_placeHolder= [NSString stringWithFormat:ASLocalizedString(@"想和大家分享些什么呢?(正文不能多于%ld字)"),self.textMaxlength] ;
  163. }
  164. if ([name isEqualToString:@"dynaic_img_length"]) {
  165. self.maxCount =
  166. self.imgMaxCount = [dict[@"value"] integerValue];
  167. }
  168. }
  169. } FailureBlock:^(NSError *error) {
  170. }];
  171. }
  172. - (void)initNavView{
  173. self.closeBtn = ({
  174. UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
  175. [btn setImage:[UIImage imageNamed:@"退出"] forState:UIControlStateNormal];
  176. [btn addTarget:self action:@selector(closeButtonClick) forControlEvents:UIControlEventTouchUpInside];
  177. btn;
  178. });
  179. [self.view addSubview:self.closeBtn];
  180. [self.closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  181. make.top.mas_equalTo(kTopHeight - kRealValue(40));
  182. make.left.equalTo(@12);
  183. make.width.height.mas_equalTo(kRealValue(40));
  184. }];
  185. }
  186. /**
  187. * 初始化视图
  188. */
  189. - (void)initViews{
  190. self.mainScrollView.frame = CGRectMake(0,(kNavigationBarHeight+kStatusBarHeight) , kScreenW, kScreenH-(kNavigationBarHeight+kStatusBarHeight)-(IPHONE_X ? 34 : 0));
  191. [self.view addSubview:self.mainScrollView];
  192. // self.titleTextView.frame = CGRectMake(0, 10, kScreenW, 30);
  193. self.noteTextView.frame = CGRectMake(15,0, kScreenW - 30, 130);
  194. [self.mainScrollView addSubview:self.noteTextView];
  195. //数字
  196. self.contentNumL.frame = CGRectMake(kScreenW / 2, self.noteTextView.bottom - kRealValue(20) - 5, kScreenW / 2 - kRealValue(25), kRealValue(20));
  197. self.contentNumL.text = [NSString stringWithFormat:@"0/%ld",self.textMaxlength];
  198. [self.mainScrollView addSubview:self.contentNumL];
  199. CGFloat viewWidth = (kScreenW - 10 * 4) / 3;
  200. self.addImgBtn.frame = CGRectMake(kRealValue(10), self.noteTextView.bottom + 10, viewWidth, viewWidth);
  201. [self.mainScrollView addSubview:self.addImgBtn];
  202. self.pickerCollectionView.hidden = YES;
  203. // [self updatePickerViewFrameY:self.contentNumL.bottom+10];
  204. CGFloat height = 33;
  205. NSString * locationStr = ASLocalizedString(@" 定位");
  206. // if (self.BuguLive.locationCity != nil && ![self.BuguLive.locationCity isEqualToString:@""]) {
  207. // locationStr = self.BuguLive.locationCity;
  208. // }
  209. STBMKCenter *stBMKCenter = [STBMKCenter shareManager];
  210. if (!stBMKCenter.districtStr ||stBMKCenter.districtStr.length<2) {
  211. }else{
  212. locationStr = stBMKCenter.districtStr;
  213. }
  214. NSArray * titleArr = @[ASLocalizedString(@"话题"),locationStr,ASLocalizedString(@"匿名")];
  215. NSArray * imageArr = @[ASLocalizedString(@"话题"),ASLocalizedString(@"济南市"),ASLocalizedString(@"匿名")];
  216. UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, self.addImgBtn.bottom + 10, kScreenW, 190)];
  217. view.backgroundColor = UIColor.clearColor;
  218. [self.mainScrollView addSubview:view];
  219. self.centerView = view;
  220. for (int i = 0; i < 3; i ++) {
  221. UIView * aview = [[UIView alloc]initWithFrame:CGRectMake(15, 10+(height+10)*i, kScreenW - 30, height)];
  222. aview.backgroundColor = [UIColor.whiteColor colorWithAlphaComponent:0.4];
  223. aview.layer.cornerRadius = height/2.0;
  224. aview.layer.masksToBounds = YES;
  225. [view addSubview:aview];
  226. QMUIButton *leftBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  227. leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  228. [leftBtn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
  229. leftBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  230. [leftBtn setTitle:titleArr[i] forState:UIControlStateNormal];
  231. leftBtn.imagePosition = QMUIButtonImagePositionLeft;
  232. [leftBtn setImage:[UIImage imageNamed:imageArr[i]] forState:UIControlStateNormal];
  233. leftBtn.spacingBetweenImageAndTitle = 3;
  234. leftBtn.userInteractionEnabled = NO;
  235. // if (i == 1) {
  236. // [leftBtn addTarget:self action:@selector(locationButtonClick) forControlEvents:UIControlEventTouchUpInside];
  237. //
  238. // }
  239. if (i == 0) {
  240. //添加一个隐藏的 topicBtn
  241. QMUIButton *topicBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  242. topicBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  243. topicBtn.imagePosition = QMUIButtonImagePositionRight;
  244. [topicBtn setImage:[UIImage imageNamed:@"删除话题"] forState:UIControlStateNormal];
  245. topicBtn.spacingBetweenImageAndTitle = 15;
  246. topicBtn.frame = CGRectMake(kScreenW-100-10, 15, 100, 24);
  247. topicBtn.layer.cornerRadius = 12;
  248. topicBtn.clipsToBounds = YES;
  249. topicBtn.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
  250. [topicBtn setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  251. topicBtn.hidden = YES;
  252. [topicBtn addTarget:self action:@selector(deleteTopicButtonClick) forControlEvents:UIControlEventTouchUpInside];
  253. [aview addSubview:topicBtn];
  254. self.topicBtn = topicBtn;
  255. UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(topicViewTapped)];
  256. [aview addGestureRecognizer:tapRecognizer];
  257. }
  258. [aview addSubview:leftBtn];
  259. if (i == 1) {
  260. self.locationBtn = leftBtn;
  261. }
  262. [leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  263. make.left.equalTo(@10);
  264. make.centerY.equalTo(@0);
  265. make.width.equalTo(@200);
  266. }];
  267. QMUIButton *rightBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  268. rightBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  269. if (i == 0) {
  270. [rightBtn setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  271. [rightBtn setTitle:ASLocalizedString(@"参与话题,让更多人看到")forState:UIControlStateNormal];
  272. rightBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  273. rightBtn.imagePosition = QMUIButtonImagePositionRight;
  274. [rightBtn setImage:[UIImage imageNamed:@"进入"] forState:UIControlStateNormal];
  275. rightBtn.spacingBetweenImageAndTitle = 16;
  276. rightBtn.userInteractionEnabled = NO;
  277. self.topicTipBtn = rightBtn;
  278. } else {
  279. [rightBtn setImage:[UIImage imageNamed:@"关闭"] forState:UIControlStateNormal];
  280. [rightBtn setImage:[UIImage imageNamed:@"打开"] forState:UIControlStateSelected];
  281. [rightBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  282. }
  283. rightBtn.tag = i;
  284. [aview addSubview:rightBtn];
  285. [rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  286. make.right.equalTo(@(-10));
  287. make.centerY.equalTo(@0);
  288. make.width.equalTo(@180);
  289. }];
  290. }
  291. self.releaseeBtn = ({
  292. UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
  293. [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
  294. btn.titleLabel.font = [UIFont systemFontOfSize:16];
  295. [btn setTitle:ASLocalizedString(@"发布")forState:UIControlStateNormal];
  296. [btn setBackgroundImage:[UIImage imageNamed:@"widthBtnBg"] forState:UIControlStateNormal];
  297. [btn addTarget:self action:@selector(releaseeButtonClick) forControlEvents:UIControlEventTouchUpInside];
  298. btn;
  299. });
  300. [self.mainScrollView addSubview:self.releaseeBtn];
  301. [self.releaseeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  302. make.top.mas_equalTo(view.mas_bottom).mas_offset(60);
  303. make.left.mas_equalTo(62);
  304. make.right.mas_equalTo(-62);
  305. make.height.mas_equalTo(45);
  306. }];
  307. UIView * toolsView = [[UIView alloc]init];
  308. [self.view addSubview:toolsView];
  309. toolsView.frame = CGRectMake(0,self.mainScrollView.bottom , kScreenW, kRealValue(44) + MG_BOTTOM_MARGIN);
  310. self.toolView = toolsView;
  311. self.toolView.backgroundColor = kWhiteColor;
  312. self.toolView.hidden = YES;
  313. // [self.view bringSubviewToFront:self.toolView];
  314. NSArray * imageToolArr = @[ASLocalizedString(@"照片"),ASLocalizedString(@"视频")];
  315. // ,@"@"];
  316. for (int i = 0; i < imageToolArr.count; i ++) {
  317. QMUIButton *Btn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  318. [Btn setImage:[UIImage imageNamed:imageToolArr[i]] forState:UIControlStateNormal];
  319. [Btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  320. Btn.tag = i+10;
  321. [toolsView addSubview:Btn];
  322. Btn.frame = CGRectMake(10+(26+20)*i, 10 + MG_TOP_MARGIN / 2, 26, 26);
  323. if (i == 2) {
  324. self.atBtn = Btn;
  325. }
  326. }
  327. [self.emojiView mas_makeConstraints:^(MASConstraintMaker *make) {
  328. make.width.and.left.mas_equalTo(0);
  329. make.height.mas_equalTo(kChatBarViewHeight);
  330. make.top.mas_equalTo(kScreenH);
  331. }];
  332. }
  333. - (CGSize)preferredSizeWithMaxWidth:(CGFloat)maxWidth view:(UIButton *)btn
  334. {
  335. CGSize size = [btn sizeThatFits:CGSizeMake(maxWidth, 24)] ;
  336. return CGSizeMake(size.width +25, size.height);
  337. }
  338. - (void)deleteTopicButtonClick{
  339. self.topicBtn.hidden = YES;
  340. self.topicTipBtn.hidden = NO;
  341. self.selectedTopicID = @"";
  342. }
  343. - (void)locationButtonClick{
  344. [FanweMessage alert:ASLocalizedString(@"请在设置->隐私->定位服务->本App下选择使用期间")];
  345. }
  346. - (void)topicViewTapped{
  347. //进入话题页面
  348. ReleaseTopicVC *tmpController = [[ReleaseTopicVC alloc]init];
  349. __weak __typeof(self)weakSelf = self;;
  350. tmpController.releaseTopicBlock = ^(MGDynamicTopicModel * _Nonnull topic) {
  351. weakSelf.topicTipBtn.hidden = YES;
  352. weakSelf.topicBtn.hidden = NO;
  353. weakSelf.selectedTopicID = topic.t_id;
  354. [weakSelf.topicBtn setTitle:[NSString stringWithFormat:@"#%@#",topic.name] forState:UIControlStateNormal];
  355. CGSize btnSize = [self preferredSizeWithMaxWidth:kScreenW-100 view:weakSelf.topicBtn];
  356. weakSelf.topicBtn.frame = CGRectMake(kScreenW-btnSize.width-10, 15, btnSize.width, 24);
  357. };
  358. [self.navigationController pushViewController:tmpController animated:YES];
  359. //选择话题后,设置frame
  360. }
  361. - (void)initTopic{
  362. if (self.topic) {
  363. self.topicTipBtn.hidden = YES;
  364. self.topicBtn.hidden = NO;
  365. if (![BGUtils isBlankString:self.topic.id]) {
  366. self.selectedTopicID = self.topic.id;
  367. }else{
  368. self.selectedTopicID = self.topic.t_id;
  369. }
  370. [self.topicBtn setTitle:[NSString stringWithFormat:@"#%@#",self.topic.name] forState:UIControlStateNormal];
  371. CGSize btnSize = [self preferredSizeWithMaxWidth:kScreenW-100 view:self.topicBtn];
  372. self.topicBtn.frame = CGRectMake(kScreenW-btnSize.width-10, 15, btnSize.width, 24);
  373. }
  374. }
  375. - (void)buttonClick:(UIButton *)sender{
  376. NSLog(ASLocalizedString(@"按钮===========%ld"),(long)sender.tag);
  377. [self.noteTextView resignFirstResponder];
  378. switch (sender.tag) {
  379. case 1:
  380. {//定位
  381. sender.selected = !sender.selected;
  382. self.showLocation = !self.showLocation;
  383. if (sender.selected) {
  384. [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"定位中...")];
  385. //加载地图
  386. [self startLocation];
  387. } else {
  388. [self.locationBtn setTitle:ASLocalizedString(@"定位")forState:UIControlStateNormal];
  389. }
  390. }
  391. break;
  392. case 2:
  393. {//匿名
  394. sender.selected = !sender.selected;
  395. self.hidName = !self.hidName;
  396. self.atBtn.hidden = (sender.selected == YES);
  397. }
  398. break;
  399. case 10:
  400. {//选择图片 图片和视频不能共存
  401. [self addNewImg];
  402. if (self.pickerCollectionView.hidden == YES) {
  403. self.pickerCollectionView.hidden = NO;
  404. }
  405. [self updatePickerViewFrameY:self.noteTextView.bottom+10];
  406. self.centerView.frame = CGRectMake(0, self.pickerCollectionView.bottom+20, kScreenW, 163);
  407. }
  408. break;
  409. case 11:
  410. {//选择视频 图片和视频不能共存
  411. [self addNewVideo];
  412. if (self.pickerCollectionView.hidden == YES) {
  413. self.pickerCollectionView.hidden = NO;
  414. }
  415. self.addImgBtn.hidden = YES;
  416. [self updatePickerViewFrameY:self.noteTextView.bottom+10];
  417. self.centerView.frame = CGRectMake(0, self.pickerCollectionView.bottom+20, kScreenW, 163);
  418. }
  419. break;
  420. // case 12:
  421. // {//弹出表情
  422. // if ([self.titleTextView isFirstResponder]) {
  423. // [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"只有内容部分才能发表情")];
  424. // }else{
  425. //// [self showFaceView:YES];
  426. //
  427. // }
  428. //
  429. //
  430. //
  431. // }
  432. // break;
  433. case 12:
  434. {//@先不加
  435. /*
  436. NSInteger length = self.noteTextView.text.length;
  437. ReleaseAtPeopleVC *tmpController = [[ReleaseAtPeopleVC alloc]init];
  438. tmpController.releaseAtPeopleBlock = ^(PersonCenterUserModel * _Nonnull user) {
  439. UITextView *textView = self.noteTextView;
  440. NSString *insertString = [NSString stringWithFormat:kATFormat,user.nick_name];
  441. NSMutableString *string = [NSMutableString stringWithString:textView.text];
  442. [string insertString:insertString atIndex:length];
  443. self.noteTextView.text = string;
  444. [self.noteTextView becomeFirstResponder];
  445. textView.selectedRange = NSMakeRange(length + insertString.length, 0);
  446. };
  447. [self.navigationController pushViewController:tmpController animated:YES];
  448. */
  449. }
  450. break;
  451. default:
  452. break;
  453. }
  454. }
  455. -(void)startLocation{
  456. if ([CLLocationManager locationServicesEnabled]) {//判断定位操作是否被允许
  457. self.locationManager = [[CLLocationManager alloc] init];
  458. self.locationManager.delegate = self;//遵循代理
  459. self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
  460. self.locationManager.distanceFilter = 10.0f;
  461. [_locationManager requestWhenInUseAuthorization];//使用程序其间允许访问位置数据(iOS8以上版本定位需要)
  462. [self.locationManager startUpdatingLocation];//开始定位
  463. }else{//不能定位用户的位置的情况再次进行判断,并给与用户提示
  464. //1.提醒用户检查当前的网络状况
  465. //2.提醒用户打开定位开关
  466. [[BGHUDHelper sharedInstance] syncStopLoading];
  467. }
  468. }
  469. - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
  470. //当前所在城市的坐标值
  471. CLLocation *currLocation = [locations lastObject];
  472. NSLog(ASLocalizedString(@"经度=%f 纬度=%f 高度=%f"), currLocation.coordinate.latitude, currLocation.coordinate.longitude, currLocation.altitude);
  473. //根据经纬度反向地理编译出地址信息
  474. CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
  475. [geoCoder reverseGeocodeLocation:currLocation completionHandler:^(NSArray *placemarks, NSError *error) {
  476. for (CLPlacemark * placemark in placemarks) {
  477. NSDictionary *address = [placemark addressDictionary];
  478. // Country(国家) State(省) City(市)
  479. NSLog(@"#####%@",address);
  480. NSLog(@"%@", [address objectForKey:@"Country"]);
  481. NSLog(@"%@", [address objectForKey:@"State"]);
  482. NSLog(@"%@", [address objectForKey:@"City"]);
  483. NSString * location = [address objectForKey:@"City"];
  484. self.city = location;
  485. [self.locationBtn setTitle:location forState:UIControlStateNormal];
  486. [[BGHUDHelper sharedInstance] syncStopLoading];
  487. }
  488. }];
  489. }
  490. -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
  491. [[BGHUDHelper sharedInstance] syncStopLoading];
  492. if ([error code] == kCLErrorDenied){
  493. //访问被拒绝
  494. [FanweMessage alertHUD:ASLocalizedString(@"访问被拒绝")];
  495. }
  496. if ([error code] == kCLErrorLocationUnknown) {
  497. //无法获取位置信息
  498. [FanweMessage alertHUD:ASLocalizedString(@"无法获取位置信息")];
  499. }
  500. }
  501. - (void)pickerViewFrameChanged{
  502. if (self.arrSelected.count > 0) {
  503. self.addImgBtn.hidden = YES;
  504. [self updatePickerViewFrameY:self.noteTextView.bottom+10];
  505. }else{
  506. self.addImgBtn.hidden = NO;
  507. [self updatePickerViewFrameY:self.addImgBtn.bottom+10];
  508. }
  509. [self updateViewsFrame];
  510. }
  511. - (void)updateViewsFrame{
  512. self.centerView.frame = CGRectMake(0, self.pickerCollectionView.bottom+20, kScreenW, 163);
  513. // allViewHeight = noteTextHeight + [self getPickerViewFrame].size.height + 30 + 100;
  514. self.mainScrollView.contentSize = CGSizeMake(0,[self getPickerViewFrame].size.height+140+20+190+20 + 45 + 60 + 50);
  515. }
  516. - (void)closeButtonClick{
  517. if (self.noteTextView.text.length == 0 && self.bigImageArray.count < 1 && self.arrSelected.count < 1) {
  518. [self dismissViewControllerAnimated:YES completion:nil];
  519. return;
  520. }
  521. NSLog(ASLocalizedString(@"取消"));
  522. @autoreleasepool {
  523. __weak typeof(self)weakself =self;
  524. [FanweMessage alertController:ASLocalizedString(@"有修改,是否放弃上传")viewController:self destructiveAction:^{
  525. [weakself dismissViewControllerAnimated:YES completion:nil];
  526. } cancelAction:^{
  527. }];
  528. // __weak typeof(self)weakself =self;
  529. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  530. // UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:nil];
  531. // UIAlertAction *actionGiveUpPublish = [UIAlertAction actionWithTitle:ASLocalizedString(@"放弃上传")style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  532. // [weakself dismissViewControllerAnimated:YES completion:nil];
  533. // }];
  534. // [alertController addAction:actionCacel];
  535. // [alertController addAction:actionGiveUpPublish];
  536. // [self presentViewController:alertController animated:YES completion:nil];
  537. // actionCacel =nil;
  538. // actionGiveUpPublish =nil;
  539. // alertController =nil;
  540. }
  541. }
  542. #pragma mark -发布
  543. - (void)releaseeButtonClick{
  544. // if (self.noteTextView.text.length<20) {
  545. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"不能少于20字哦")preferredStyle:UIAlertControllerStyleAlert];
  546. // UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil];
  547. // [alertController addAction:actionCacel];
  548. // [self presentViewController:alertController animated:YES completion:nil];
  549. // return;
  550. // }
  551. if (self.noteTextView.text.length>self.textMaxlength) {
  552. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"超出文字限制")preferredStyle:UIAlertControllerStyleAlert];
  553. UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil];
  554. [alertController addAction:actionCacel];
  555. [self presentViewController:alertController animated:YES completion:nil];
  556. return;
  557. }
  558. [self submitToServer];
  559. }
  560. #pragma mark - 上传数据到服务器前将图片转data(上传服务器用form表单:未写)
  561. - (void)submitToServer{
  562. if (self.arrSelected >0)
  563. {
  564. [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在上传")];
  565. __block typeof(self)blockself =self;
  566. [self PhassetgetBigImageArray:self.arrSelected isSubmit:YES callBack:^(NSArray *ary, bool isImg) {
  567. if (self.arrSelected.count == ary.count)
  568. {
  569. NSMutableArray *smallImageDataArray = [ary copy];
  570. [blockself submitToserverWith:smallImageDataArray isImg:isImg];
  571. }
  572. }];
  573. // [self PhassetgetBigImageArray:self.arrSelected callBack:^(NSArray *ary, bool isImg) {
  574. //
  575. // }];
  576. }else
  577. {
  578. self.type = BGMediaTypeText;
  579. __weak __typeof(self)weakSelf = self;
  580. NSString * location = @"";
  581. if (self.showLocation) {
  582. location = self.city;
  583. }
  584. if ([BGUtils isBlankString:_noteTextView.text]) {
  585. [[BGHUDHelper sharedInstance]loading:ASLocalizedString(@"内容不能为空!")delay:1.0f execute:nil completion:nil];
  586. return;
  587. }
  588. [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在上传")];
  589. [self.bzoneLogic addDynamicType:self.type content:_noteTextView.text media:@[] cover_url:@"" no_name:self.hidName themeID:self.selectedTopicID address:location media_attr:@"" at:@"" shop_id:@"" shop_title:@"" Success:^(BOOL isFinished) {
  590. [[BGHUDHelper sharedInstance]syncStopLoading];
  591. if (isFinished) {
  592. if (weakSelf.postFinishBlock) {
  593. weakSelf.postFinishBlock(isFinished);
  594. }
  595. [weakSelf dismissViewControllerAnimated:YES completion:nil];
  596. }
  597. }];
  598. }
  599. }
  600. //-(void)initJZPlayerWithUrl:(NSURL *)url{
  601. // _jzPlayer = [[JZVideoPlayerView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 300) contentURL:url];
  602. // _jzPlayer.delegate = self;
  603. // [self.view addSubview:_jzPlayer];
  604. // [_jzPlayer play];
  605. //}
  606. - (void)submitToserverWith:(NSArray * )imgary isImg:(BOOL)isImg
  607. {
  608. if (imgary.count == 0 ) {
  609. }
  610. NSString *type = @"0";
  611. if (isImg) {
  612. type = @"0";
  613. }else{
  614. type = @"1";
  615. }
  616. //上传照片
  617. // [[BGHUDHelper sharedInstance]syncStopLoading];
  618. [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在上传数据中...")];
  619. //上传音频,没有图片时
  620. __weak __typeof(self)weakSelf = self;
  621. if ([type isEqualToString:@"1"]) {
  622. //上传视频
  623. self.type = BGMediaTypeVideo;
  624. PHAsset* phasset = self.arrSelected[0];
  625. PHVideoRequestOptions *optionForCache = [[PHVideoRequestOptions alloc]init];
  626. optionForCache.version = PHVideoRequestOptionsVersionOriginal;
  627. optionForCache.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
  628. optionForCache.networkAccessAllowed = YES;
  629. [[PHImageManager defaultManager] requestAVAssetForVideo:phasset options:optionForCache resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
  630. AVURLAsset *urlAsset = (AVURLAsset *)asset;
  631. CMTime time = [urlAsset duration];
  632. int seconds = ceil(time.value/time.timescale);
  633. NSLog(ASLocalizedString(@"视频时长%d"),seconds);
  634. self.selectedVideoDurationTime = seconds;
  635. if ((int)seconds <3) {
  636. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"选取视频时长太小")];
  637. //关闭当前的模态视图
  638. [self dismissViewControllerAnimated:YES completion:^{
  639. [self.navigationController popViewControllerAnimated:YES];
  640. }];
  641. return;
  642. }else if((int)seconds >=self.videoDurationTime) {
  643. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"选取视频时长太大")];
  644. //关闭当前的模态视图
  645. [self dismissViewControllerAnimated:YES completion:^{
  646. [self.navigationController popViewControllerAnimated:YES];
  647. }];
  648. return;
  649. }else{
  650. [self uploadVideo];
  651. }
  652. }];
  653. }else{
  654. self.type = BGMediaTypeImage;
  655. NSLog(@"%@",self.bigImageArray);
  656. NSMutableArray<MultipleFileUploadsModel *> *arr = [NSMutableArray array];
  657. for (int i =0 ; i<self.bigImageArray.count; i++) {
  658. MultipleFileUploadsModel *model = [[MultipleFileUploadsModel alloc] init];
  659. model.fileName = [NSString stringWithFormat:@"uploadpng%d.png",i];
  660. model.data =self.bigImageArray[i];
  661. [arr addObject:model];
  662. }
  663. [[BGHUDHelper sharedInstance]syncStopLoading];
  664. [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在上传图片...")];
  665. NSString * location = @"";
  666. if (self.showLocation) {
  667. location = self.city;
  668. }
  669. [self.multipleFileUploads uploadFile:arr done:^(NSArray<NSString *> * _Nonnull urlStrMArray) {
  670. [weakSelf.bzoneLogic addDynamicType:self.type content:_noteTextView.text media:urlStrMArray cover_url:@"" no_name:self.hidName themeID:self.selectedTopicID address:location media_attr:[NSString stringWithFormat:@"%lu",(unsigned long)urlStrMArray.count] at:@"" shop_id:@"" shop_title:@"" Success:^(BOOL isFinished) {
  671. [[BGHUDHelper sharedInstance]syncStopLoading];
  672. if (isFinished) {
  673. if (weakSelf.postFinishBlock) {
  674. weakSelf.postFinishBlock(isFinished);
  675. }
  676. [[BGHUDHelper sharedInstance]syncStopLoading];
  677. [weakSelf dismissViewControllerAnimated:YES completion:nil];
  678. }
  679. }];
  680. }];
  681. // [_ossManager showUploadOfOssServiceOfDataMarray:self.bigImageArray andSTDynamicSelectType:STDynamicSelectPhoto andComplete:^(BOOL finished, NSMutableArray<NSString *> *urlStrMArray) {
  682. // NSLog(@"%@",urlStrMArray);
  683. // [[BGHUDHelper sharedInstance]syncStopLoading];
  684. // [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在上传图片...")];
  685. // NSString * location = @"";
  686. // if (self.showLocation) {
  687. // location = self.city;
  688. // }
  689. // [weakSelf.bzoneLogic addDynamicType:self.type content:_noteTextView.text media:urlStrMArray cover_url:@"" no_name:self.hidName themeID:self.selectedTopicID address:location media_attr:[NSString stringWithFormat:@"%lu",(unsigned long)urlStrMArray.count] at:@""shop_id:@"" shop_title:@"" Success:^(BOOL isFinished) {
  690. // [[BGHUDHelper sharedInstance]syncStopLoading];
  691. // if (isFinished) {
  692. // if (weakSelf.postFinishBlock) {
  693. // weakSelf.postFinishBlock(isFinished);
  694. // }
  695. // [[BGHUDHelper sharedInstance]syncStopLoading];
  696. // [weakSelf dismissViewControllerAnimated:YES completion:nil];
  697. // }
  698. // }];
  699. // }];
  700. }
  701. }
  702. - (void)uploadVideo{
  703. //视频类型的动态
  704. __weak __typeof(self)weakSelf = self;
  705. UIImage *coverimg =self.imageArray[0];
  706. NSData *imageData = UIImagePNGRepresentation(coverimg);
  707. // dispatch_group_t group = dispatch_group_create();
  708. __block NSString *coverUrl;
  709. // __block NSString *videoUrl;
  710. // __block NSString *audioUrl = @"";
  711. // __block typeof(self)blockself =self;
  712. NSArray *coverArr = [NSArray arrayWithObjects:imageData, nil];
  713. NSMutableArray *uploadArr = [NSMutableArray array];
  714. //添加封面
  715. MultipleFileUploadsModel *photoModel = [[MultipleFileUploadsModel alloc] init];
  716. photoModel.fileName = @"photo.png";
  717. photoModel.data = imageData;
  718. [uploadArr addObject:photoModel];
  719. //添加视频
  720. MultipleFileUploadsModel *videoModel = [[MultipleFileUploadsModel alloc] init];
  721. videoModel.fileName = @"vidoe.mov";
  722. videoModel.data = self.bigImageArray[0];
  723. [uploadArr addObject:videoModel];
  724. [self.multipleFileUploads uploadFile:uploadArr done:^(NSArray<NSString *> * _Nonnull urlArr) {
  725. [[BGHUDHelper sharedInstance]syncStopLoading];
  726. if(urlArr.count < 2)
  727. {
  728. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"上传失败")];
  729. }
  730. else
  731. {
  732. NSString *videoUrl;
  733. if([urlArr[0] containsString:@".png"])
  734. {
  735. coverUrl = urlArr[0];
  736. videoUrl = urlArr[1];
  737. }
  738. else
  739. {
  740. coverUrl = urlArr[1];
  741. videoUrl = urlArr[0];
  742. }
  743. NSString * location = @"";
  744. if (self.showLocation) {
  745. location = self.city;
  746. }
  747. [weakSelf.bzoneLogic addDynamicType:self.type content:_noteTextView.text media:@[videoUrl] cover_url:coverUrl no_name:self.hidName themeID:self.selectedTopicID address:location media_attr:[NSString stringWithFormat:@"%ld",(long)self.selectedVideoDurationTime] at:@"" shop_id:@"" shop_title:@"" Success:^(BOOL isFinished) {
  748. if (isFinished) {
  749. if (weakSelf.postFinishBlock) {
  750. weakSelf.postFinishBlock(isFinished);
  751. }
  752. [[BGHUDHelper sharedInstance]syncStopLoading];
  753. [weakSelf dismissViewControllerAnimated:YES completion:nil];
  754. }
  755. }];
  756. }
  757. }];
  758. // [_ossManager showUploadOfOssServiceOfDataMarray:coverArr andSTDynamicSelectType:STDynamicSelectPhoto andComplete:^(BOOL finished, NSMutableArray<NSString *> *urlStrMArray) {
  759. // NSLog(@"%@",urlStrMArray);
  760. //
  761. // coverUrl = urlStrMArray.firstObject;
  762. //
  763. //
  764. // [[BGHUDHelper sharedInstance]syncStopLoading];
  765. // [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在上传视频...")];
  766. // NSLog(@"%@",self.bigImageArray);
  767. //
  768. //// NSData *data = self.bigImageArray.firstObject;
  769. //
  770. // [self.ossManager showUploadOfOssServiceOfDataMarray:self.bigImageArray
  771. // andSTDynamicSelectType:STDynamicSelectVideo
  772. // andComplete:^(BOOL finished,
  773. // NSMutableArray<NSString *> *urlStrMArrayVideo) {
  774. //
  775. // [[BGHUDHelper sharedInstance]syncStopLoading];
  776. //
  777. // if(urlStrMArrayVideo.count>0)
  778. // {
  779. // NSString * location = @"";
  780. // if (self.showLocation) {
  781. // location = self.city;
  782. // }
  783. //
  784. //
  785. //
  786. // [weakSelf.bzoneLogic addDynamicType:self.type content:_noteTextView.text media:@[urlStrMArrayVideo.firstObject] cover_url:coverUrl no_name:self.hidName themeID:self.selectedTopicID address:location media_attr:[NSString stringWithFormat:@"%ld",(long)self.selectedVideoDurationTime] at:@"" shop_id:@"" shop_title:@"" Success:^(BOOL isFinished) {
  787. //
  788. // if (isFinished) {
  789. // if (weakSelf.postFinishBlock) {
  790. // weakSelf.postFinishBlock(isFinished);
  791. // }
  792. // [[BGHUDHelper sharedInstance]syncStopLoading];
  793. // [weakSelf dismissViewControllerAnimated:YES completion:nil];
  794. // }
  795. //
  796. // }];
  797. //
  798. // }
  799. // }];
  800. // }];
  801. }
  802. #pragma mark - chat Emoji View Delegate
  803. - (void)chatEmojiViewSelectEmojiIcon:(EmojiObj *)objIcon
  804. {
  805. NSCharacterSet *nonDigits = [[NSCharacterSet decimalDigitCharacterSet] invertedSet];
  806. int emojiID = [[objIcon.emojiName stringByTrimmingCharactersInSet:nonDigits] intValue];
  807. [self.noteTextView appendFace:emojiID];
  808. // [self.chatBar updateChatBarConstraintsIfNeededShouldCacheText:YES];
  809. }
  810. - (void)chatEmojiViewTouchUpinsideDeleteButton
  811. {
  812. //点击了删除表情
  813. if (self.noteTextView.text.length > 0)
  814. {
  815. NSRange range = self.noteTextView.selectedRange;
  816. NSInteger location = (NSInteger) range.location;
  817. if (location == 0)
  818. {
  819. return;
  820. }
  821. range.location = location - 1;
  822. range.length = 1;
  823. NSMutableAttributedString *attStr = [self.noteTextView.attributedText mutableCopy];
  824. [attStr deleteCharactersInRange:range];
  825. self.noteTextView.attributedText = attStr;
  826. self.noteTextView.selectedRange = range;
  827. }
  828. }
  829. - (void)chatEmojiViewTouchDownDeleteButton
  830. {
  831. self.noteTextView.text = nil;
  832. // [self.chatBar updateChatBarConstraintsIfNeededShouldCacheText:YES];
  833. }
  834. - (void)chatEmojiViewTouchUpinsideSendButton
  835. {
  836. //表情键盘:点击发送表情
  837. if (self.noteTextView.text.length == 0)
  838. {
  839. [SVProgressHUD showErrorWithStatus:ASLocalizedString(@"请先输入发送内容")];
  840. return;
  841. }
  842. else
  843. {
  844. // [self willSendThisText:[self.noteTextView getSendTextStr]];
  845. }
  846. }
  847. #pragma mark - UITextViewDelegate
  848. /*由于联想输入的时候,函数textView:shouldChangeTextInRange:replacementText:无法判断字数,
  849. 因此使用textViewDidChange对TextView里面的字数进行判断
  850. */
  851. - (void)textViewDidChange:(UITextView *)textView{
  852. if (textView == self.noteTextView) {
  853. self.contentNumL.text = [NSString stringWithFormat:@"%ld/%ld",self.noteTextView.text.length,self.textMaxlength];
  854. if (self.noteTextView.text.length > self.textMaxlength) {
  855. // textView.text = [textView.text substringToIndex:199];
  856. self.noteTextView.text = [textView.text substringToIndex:self.textMaxlength];
  857. self.contentNumL.text = [NSString stringWithFormat:@"%ld/%ld",self.noteTextView.text.length,self.textMaxlength];
  858. [FanweMessage alert:ASLocalizedString(@"提示")message:[NSString stringWithFormat:ASLocalizedString(@"正文不能多于%ld字"),self.textMaxlength] isHideTitle:NO destructiveAction:nil];
  859. }
  860. }
  861. }
  862. -(void)textViewDidEndEditing:(UITextView *)textView{
  863. if (textView == self.noteTextView) {
  864. if (self.noteTextView.text.length > self.textMaxlength) {
  865. [FanweMessage alert:ASLocalizedString(@"提示")message:[NSString stringWithFormat:ASLocalizedString(@"正文不能多于%ld字"),self.textMaxlength] isHideTitle:NO destructiveAction:nil];
  866. textView.text = [textView.text substringToIndex:self.textMaxlength];
  867. self.contentNumL.text = [NSString stringWithFormat:@"%ld/%ld",self.noteTextView.text.length,self.textMaxlength];
  868. }
  869. }
  870. }
  871. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
  872. if (textView == self.titleTextView) {
  873. return YES;
  874. }
  875. if ([text isEqualToString:@""])
  876. {
  877. NSRange selectRange = textView.selectedRange;
  878. if (selectRange.length > 0)
  879. {
  880. //用户长按选择文本时不处理
  881. return YES;
  882. }
  883. // 判断删除的是一个@中间的字符就整体删除
  884. NSMutableString *string = [NSMutableString stringWithString:textView.text];
  885. NSArray *matches = [self findAllAt];
  886. BOOL inAt = NO;
  887. NSInteger index = range.location;
  888. for (NSTextCheckingResult *match in matches)
  889. {
  890. NSRange newRange = NSMakeRange(match.range.location + 1, match.range.length - 1);
  891. if (NSLocationInRange(range.location, newRange))
  892. {
  893. inAt = YES;
  894. index = match.range.location;
  895. [string replaceCharactersInRange:match.range withString:@""];
  896. break;
  897. }
  898. }
  899. if (inAt)
  900. {
  901. textView.text = string;
  902. textView.selectedRange = NSMakeRange(index, 0);
  903. return NO;
  904. }
  905. }
  906. //判断是回车键就
  907. if ([text isEqualToString:@"\n"])
  908. {
  909. return NO;
  910. }
  911. return YES;
  912. }
  913. //- (void)textViewDidChange:(UITextView *)textView{
  914. // UITextRange *selectedRange = textView.markedTextRange;
  915. // NSString *newText = [textView textInRange:selectedRange];
  916. //
  917. // if (newText.length < 1)
  918. // {
  919. // // 高亮输入框中的@
  920. // UITextView *textView = self.noteTextView;
  921. // NSRange range = textView.selectedRange;
  922. //
  923. // NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:textView.text];
  924. // [string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, string.string.length)];
  925. //
  926. // NSArray *matches = [self findAllAt];
  927. //
  928. // for (NSTextCheckingResult *match in matches)
  929. // {
  930. // [string addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#CD49FF"] range:NSMakeRange(match.range.location, match.range.length - 1)];
  931. // }
  932. //
  933. // textView.attributedText = string;
  934. // textView.selectedRange = range;
  935. // }
  936. //
  937. // //获取高亮部分
  938. // UITextPosition *pos = [textView positionFromPosition:selectedRange.start offset:0];
  939. // //如果在变化中是高亮部分在变,就不要计算字符了
  940. // if (selectedRange && pos) {
  941. // return;
  942. // }
  943. // NSString *nsTextContent = textView.text;
  944. // NSInteger existTextNum = nsTextContent.length;
  945. // if (existTextNum >self.textMaxlength){
  946. // //截取到最大位置的字符(由于超出截部分在should时被处理了所在这里这了提高效率不再判断)
  947. // NSString *s = [nsTextContent substringToIndex:self.textMaxlength];
  948. // [textView setText:s];
  949. // }
  950. // //不让显示负数
  951. //// self.showWordsNumLab.text = [NSString stringWithFormat:@"%ld/100",(MAX_LIMIT_NUMS - existTextNum)];
  952. //
  953. //}
  954. //- (void)textViewDidChangeSelection:(UITextView *)textView{
  955. //
  956. // // 光标不能点落在@词中间
  957. // NSRange range = textView.selectedRange;
  958. // if (range.length > 0)
  959. // {
  960. // // 选择文本时可以
  961. // return;
  962. // }
  963. //
  964. // NSArray *matches = [self findAllAt];
  965. //
  966. // for (NSTextCheckingResult *match in matches)
  967. // {
  968. // NSRange newRange = NSMakeRange(match.range.location + 1, match.range.length - 1);
  969. // if (NSLocationInRange(range.location, newRange))
  970. // {
  971. // textView.selectedRange = NSMakeRange(match.range.location + match.range.length, 0);
  972. // break;
  973. // }
  974. // }
  975. //}
  976. #pragma mark - Private
  977. - (NSArray<NSTextCheckingResult *> *)findAllAt
  978. {
  979. // 找到文本中所有的@
  980. NSString *string = self.noteTextView.text;
  981. NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:kATRegular options:NSRegularExpressionCaseInsensitive error:nil];
  982. NSArray *matches = [regex matchesInString:string options:NSMatchingReportProgress range:NSMakeRange(0, [string length])];
  983. return matches;
  984. }
  985. #pragma mark -
  986. - (void)viewWillAppear:(BOOL)animated {
  987. [super viewWillAppear:animated];
  988. [IQKeyboardManager sharedManager].enable = NO;
  989. [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
  990. self.navigationController.navigationBar.hidden = YES;
  991. }
  992. - (void)viewDidDisappear:(BOOL)animated{
  993. [super viewDidDisappear:animated];
  994. //停止定位
  995. }
  996. - (void)showFaceView:(BOOL)show
  997. {
  998. if (show)
  999. {
  1000. self.emojiView.hidden = NO;
  1001. [UIView animateWithDuration:0.25f
  1002. animations:^{
  1003. [self.emojiView mas_updateConstraints:^(MASConstraintMaker *make) {
  1004. make.top.mas_equalTo(self.view.mas_bottom).offset(-kChatBarViewHeight);
  1005. }];
  1006. [self.emojiView layoutIfNeeded];
  1007. }
  1008. completion:nil];
  1009. [self.emojiView mas_updateConstraints:^(MASConstraintMaker *make) {
  1010. make.top.mas_equalTo(kScreenH-kChatBarViewHeight);
  1011. }];
  1012. [self.toolView mas_updateConstraints:^(MASConstraintMaker *make) {
  1013. make.bottom.mas_equalTo(-kChatBarViewHeight-MG_BOTTOM_MARGIN);
  1014. }];
  1015. [UIView animateWithDuration:_animationDuration/4
  1016. animations:^{
  1017. [self.toolView layoutIfNeeded];
  1018. }completion:nil];
  1019. }
  1020. else if (self.emojiView.superview)
  1021. {
  1022. self.emojiView.hidden = YES;
  1023. [self.emojiView mas_remakeConstraints:^(MASConstraintMaker *make) {
  1024. make.width.and.left.mas_equalTo(self);
  1025. make.height.mas_equalTo(kChatBarViewHeight);
  1026. make.top.mas_equalTo(self.view.mas_bottom);
  1027. }];
  1028. [self.emojiView layoutIfNeeded];
  1029. }
  1030. }
  1031. -(void)clickAddImgBtn:(UIButton *)sender{
  1032. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  1033. UIAlertAction *actionImg = [UIAlertAction actionWithTitle:ASLocalizedString(@"图片")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1034. [self addNewImg];
  1035. if (self.pickerCollectionView.hidden == YES) {
  1036. self.pickerCollectionView.hidden = NO;
  1037. }
  1038. [self updatePickerViewFrameY:self.addImgBtn.bottom+10];
  1039. self.centerView.frame = CGRectMake(0, self.pickerCollectionView.bottom+20, kScreenW, 163);
  1040. }];
  1041. UIAlertAction *actionVideo = [UIAlertAction actionWithTitle:@"视频" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  1042. [self addNewVideo];
  1043. if (self.pickerCollectionView.hidden == YES) {
  1044. self.pickerCollectionView.hidden = NO;
  1045. }
  1046. [self updatePickerViewFrameY:self.addImgBtn.bottom+10];
  1047. self.centerView.frame = CGRectMake(0, self.pickerCollectionView.bottom+20, kScreenW, 163);
  1048. }];
  1049. UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  1050. }];
  1051. [alert addAction:actionCancel];
  1052. [alert addAction:actionImg];
  1053. [alert addAction:actionVideo];
  1054. [self presentViewController:alert animated:YES completion:nil];
  1055. }
  1056. #pragma mark - setter
  1057. - (UIScrollView *)mainScrollView{
  1058. if (!_mainScrollView) {
  1059. _mainScrollView = ({
  1060. UIScrollView * scrollView = [[UIScrollView alloc]init];
  1061. // scrollView.contentSize = CGSizeMake(kScreenW, kScreenH);
  1062. scrollView;
  1063. });
  1064. }
  1065. return _mainScrollView;
  1066. }
  1067. - (UITextView *)titleTextView{
  1068. if (!_titleTextView) {
  1069. _titleTextView=({
  1070. UITextView *textview=[[UITextView alloc]init];
  1071. textview.backgroundColor=[UIColor whiteColor];
  1072. textview.font=[UIFont systemFontOfSize:15];
  1073. textview.zw_placeHolder=ASLocalizedString(@"标题(选填)");
  1074. textview.textContainerInset=UIEdgeInsetsMake(10, 10, 10, 10);
  1075. // textview.delegate = self;
  1076. textview;
  1077. });
  1078. }
  1079. return _titleTextView;
  1080. }
  1081. - (ChatBarTextView *)noteTextView{
  1082. if (!_noteTextView) {
  1083. _noteTextView = ({
  1084. ChatBarTextView *textview=[[ChatBarTextView alloc]init];
  1085. textview.backgroundColor=[[UIColor whiteColor] colorWithAlphaComponent:0.4];
  1086. textview.font = [UIFont systemFontOfSize:15];
  1087. textview.delegate = self;
  1088. textview.zw_placeHolder= [NSString stringWithFormat:ASLocalizedString(@"想和大家分享些什么呢?"),self.textMaxlength] ;
  1089. textview.textContainerInset=UIEdgeInsetsMake(10, 10, 10, 10);
  1090. // textview.delegate = self;
  1091. textview.layer.cornerRadius = 10;
  1092. textview.layer.masksToBounds = YES;
  1093. textview;
  1094. });
  1095. }
  1096. return _noteTextView;
  1097. }
  1098. -(UILabel *)contentNumL{
  1099. if (!_contentNumL) {
  1100. _contentNumL = [UILabel new];
  1101. _contentNumL.font = [UIFont systemFontOfSize:15];
  1102. _contentNumL.textColor = [UIColor colorWithHexString:@"666666"];
  1103. _contentNumL.textAlignment = NSTextAlignmentRight;
  1104. }
  1105. return _contentNumL;
  1106. }
  1107. - (ChatEmojiView *)emojiView
  1108. {
  1109. if (!_emojiView)
  1110. {
  1111. ChatEmojiView *emojiView = [[ChatEmojiView alloc] init];
  1112. emojiView.hidden = YES;
  1113. emojiView.delegate = self;
  1114. emojiView.backgroundColor = [UIColor whiteColor];
  1115. [self.view addSubview:(_emojiView = emojiView)];
  1116. }
  1117. return _emojiView;
  1118. }
  1119. -(MultipleFileUploads *)multipleFileUploads
  1120. {
  1121. if(_multipleFileUploads ==nil)
  1122. {
  1123. _multipleFileUploads = [[MultipleFileUploads alloc] init];
  1124. }
  1125. return _multipleFileUploads;
  1126. }
  1127. -(UIButton *)addImgBtn{
  1128. if (!_addImgBtn) {
  1129. _addImgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  1130. [_addImgBtn setBackgroundImage:[UIImage imageNamed:@"mine_edit_addPhoto"] forState:UIControlStateNormal];
  1131. [_addImgBtn addTarget:self action:@selector(clickAddImgBtn:) forControlEvents:UIControlEventTouchUpInside];
  1132. _addImgBtn.backgroundColor = kClearColor;
  1133. }
  1134. return _addImgBtn;
  1135. }
  1136. @end