当前位置:   article > 正文

[IOS]用户聊天界面_oc 聊天界面

oc 聊天界面

用户聊天界面

Demo:http://download.csdn.net/detail/u012881779/8613413

部分代码:

  1. @interface ProcessMessage ()<UITextViewDelegate,UITableViewDataSource,UITableViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate >
  2. @property (nonatomic) float gKeyBoardH;
  3. @property (nonatomic) CGRect gTVrect;
  4. @property (weak, nonatomic) IBOutlet UIView *gSendV; //发送栏视图
  5. @property (weak, nonatomic) IBOutlet UIButton *gSendBut; //发送
  6. @property (weak, nonatomic) IBOutlet UITextView *gImputTxtV; //输入框
  7. @property (weak, nonatomic) IBOutlet UITableView *gProcessTV; //消息TV
  8. @property (strong, nonatomic) NSMutableArray *gCellHeightArr ;//cell高
  9. @property (strong, nonatomic) NSMutableArray *gMessageInfo; //消息内容
  10. @property (strong, nonatomic) VoiceInfo *gVoice; //语音
  11. @property (strong, nonatomic) PictureInfo *gPicture; //图片
  12. @property (strong, nonatomic) NSString *gMyObjectID; //自己的ID
  13. @property (strong, nonatomic) NSString *gObjectID; //交谈对象ID
  14. @property (strong, nonatomic) NSString *gUserid; //自己ID
  15. @property (strong, nonatomic) AudioRecord *mAudioRecord;
  16. @property (strong, nonatomic) AVAudioPlayer *gAudioPlayer;
  17. @property (strong, nonatomic) ProcessAudioPlay *gProcessAPlayer;
  18. @property (strong, nonatomic) IBOutlet UIView *uploadView; //加载更多视图
  19. @property (strong, nonatomic) IBOutlet UIView *uploadNilView; //表尾为空
  20. @property (weak, nonatomic) IBOutlet UIButton *tapLoadBut; //点击加载But
  21. @property (weak, nonatomic) IBOutlet UIView *loadingView; //加载View
  22. @property (weak, nonatomic) IBOutlet UILabel *titleLab;
  23. @property (nonatomic) NSInteger leftPageNum;
  24. @end
  25. @implementation ProcessMessage
  26. - (void)viewDidLoad
  27. {
  28. [super viewDidLoad];
  29. [self.view setFrame:[[UIScreen mainScreen] bounds]];
  30. if(!self.gCellHeightArr){
  31. self.gCellHeightArr = [[NSMutableArray alloc] init];
  32. }
  33. if(!self.gMessageInfo){
  34. self.gMessageInfo = [[NSMutableArray alloc] init];
  35. }
  36. [_gProcessTV setTransform:CGAffineTransformMakeRotation(M_PI)];
  37. [_gProcessTV setTableFooterView:_uploadView];
  38. [_uploadView setTransform:CGAffineTransformMakeRotation(M_PI)];
  39. //参数设置
  40. _leftPageNum = 1;
  41. _gMyObjectID = @"50";
  42. _gUserid = @"50";
  43. _gObjectID = @"60";
  44. //消息TableView
  45. [self cMessageTableView];
  46. //消息发送栏
  47. [self cMessageSend:40];
  48. //增加监听,当键盘出现或改变时收出消息
  49. [[NSNotificationCenter defaultCenter] addObserver:self
  50. selector:@selector(keyboardWillShow:)
  51. name:UIKeyboardWillShowNotification
  52. object:nil];
  53. //增加监听,当键退出时收出消息
  54. [[NSNotificationCenter defaultCenter] addObserver:self
  55. selector:@selector(keyboardWillHide:)
  56. name:UIKeyboardWillHideNotification
  57. object:nil];
  58. }
  59. //消息TableView
  60. -(void)cMessageTableView{
  61. self.gTVrect = _gProcessTV.frame;
  62. [_gProcessTV setSeparatorStyle:NO];
  63. }
  64. //消息发送栏
  65. -(void)cMessageSend:(float)sendVH{
  66. if(sendVH < 40){
  67. sendVH = 40;
  68. }else if(sendVH > 100){
  69. sendVH = 100;
  70. }
  71. if(sendVH == 60 || sendVH == 78){
  72. [_gImputTxtV setContentOffset:CGPointMake(0, 0) animated:YES];
  73. }
  74. //消息发送栏高度动态调整
  75. CGRect sendViewRect = _gSendV.frame;
  76. sendViewRect.origin.y = sendViewRect.origin.y - (sendVH-sendViewRect.size.height);
  77. sendViewRect.size.height = sendVH;
  78. [UIView animateWithDuration:0.2 animations:^{
  79. [_gSendV setFrame:sendViewRect];
  80. } completion:^(BOOL finished){}];
  81. //tablevie高度适配
  82. CGRect tvRect = _gProcessTV.frame;
  83. float tvHeight = _gSendV.frame.origin.y - tvRect.origin.y;
  84. tvRect.size.height = tvHeight;
  85. [_gProcessTV setFrame:tvRect];
  86. //发送按钮状态
  87. BOOL judge = 0;
  88. for (int i = 0; i < [_gImputTxtV.text length]; i ++) {
  89. NSString *str = [_gImputTxtV.text substringWithRange:NSMakeRange(i, 1)];
  90. if(![str isEqualToString:@" "]){
  91. if(![str isEqualToString:@"\n"]){
  92. judge = 1;
  93. }
  94. }
  95. }
  96. if(judge){
  97. [_gSendBut setBackgroundImage:[UIImage imageNamed:@"蓝按钮.png"] forState:UIControlStateNormal];
  98. [_gSendBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  99. }else{
  100. [_gSendBut setBackgroundImage:[UIImage imageNamed:@"发送按钮.png"] forState:UIControlStateNormal];
  101. [_gSendBut setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
  102. }
  103. //输入框
  104. [_gImputTxtV.layer setCornerRadius:5];
  105. [_gImputTxtV.layer setBorderWidth:1];
  106. [_gImputTxtV.layer setBorderColor:[[UIColor colorWithRed:228.0/255 green:228.0/255 blue:228.0/255 alpha:1] CGColor] ];
  107. }
  108. //发送消息button关联事件
  109. - (IBAction)downTapAction:(id)sender {
  110. UIButton *tempBut = (UIButton *)sender;
  111. if(tempBut.tag == 4100){
  112. //语音
  113. if(!_gVoice){
  114. NSArray* array = [[NSBundle mainBundle] loadNibNamed:@"VoiceInfo" owner:nil options:nil];
  115. _gVoice = (VoiceInfo*)[array objectAtIndex:0];
  116. //关联事件
  117. [_gVoice.but0 addTarget:self action:@selector(gCancelVoice:) forControlEvents:UIControlEventTouchUpInside];
  118. [_gVoice.but1 addTarget:self action:@selector(gVoiceDown:) forControlEvents:UIControlEventTouchDown];
  119. [_gVoice.but1 addTarget:self action:@selector(gVoiceInside:) forControlEvents:UIControlEventTouchUpInside];
  120. [_gVoice.but1 addTarget:self action:@selector(gVoiceOutside:) forControlEvents:UIControlEventTouchUpOutside];
  121. }
  122. [_gVoice setFrame:[[UIScreen mainScreen] bounds]];
  123. CGRect tempPicRect = _gVoice.gViewOne.frame;
  124. tempPicRect.origin.y = [[UIScreen mainScreen] bounds].size.height - tempPicRect.size.height;
  125. _gVoice.gViewOne.frame = tempPicRect;
  126. CGRect rectOne = _gVoice.frame;
  127. CGRect rectTwo = self.view.frame;
  128. float changeF = rectTwo.size.height - rectOne.size.height;
  129. rectOne.origin.y = changeF;
  130. [_gVoice setFrame:rectOne];
  131. [self.view addSubview:_gVoice];
  132. CGRect tempRect = _gVoice.frame;
  133. CGRect tempRectOne = tempRect;
  134. tempRectOne.origin.y = self.view.frame.size.height;
  135. [_gVoice setFrame:tempRectOne];
  136. //动画
  137. [_gVoice setAlpha:0];
  138. [_gVoice.gViewOne setAlpha:0];
  139. [_gVoice.gImgV setAlpha:0];
  140. [UIView animateWithDuration:0.3 animations:^{
  141. [_gVoice setFrame:tempRect];
  142. [_gVoice setAlpha:1];
  143. [_gVoice.gViewOne setAlpha:1];
  144. [_gVoice.gImgV setAlpha:0.2];
  145. } completion:^(BOOL finished){}];
  146. [self cReturnLocation];
  147. }else if(tempBut.tag == 4101){
  148. //图片
  149. if(!_gPicture){
  150. NSArray* array = [[NSBundle mainBundle] loadNibNamed:@"PictureInfo" owner:nil options:nil];
  151. _gPicture = (PictureInfo*)[array objectAtIndex:0];
  152. //关联事件
  153. [_gPicture.but0 addTarget:self action:@selector(gCancel:) forControlEvents:UIControlEventTouchUpInside];
  154. [_gPicture.but1 addTarget:self action:@selector(gPlot:) forControlEvents:UIControlEventTouchUpInside];
  155. [_gPicture.but2 addTarget:self action:@selector(gPlot:) forControlEvents:UIControlEventTouchUpInside];
  156. [_gPicture.but3 addTarget:self action:@selector(gPlot:) forControlEvents:UIControlEventTouchUpInside];
  157. }
  158. [_gPicture setFrame:[[UIScreen mainScreen] bounds]];
  159. CGRect tempPicRect = _gPicture.gViewOne.frame;
  160. tempPicRect.origin.y = [[UIScreen mainScreen] bounds].size.height - tempPicRect.size.height;
  161. _gPicture.gViewOne.frame = tempPicRect;
  162. CGRect rectOne = _gPicture.frame;
  163. CGRect rectTwo = self.view.frame;
  164. float changeF = rectTwo.size.height - rectOne.size.height;
  165. rectOne.origin.y = changeF;
  166. [_gPicture setFrame:rectOne];
  167. [self.view addSubview:_gPicture];
  168. CGRect tempRect = _gPicture.frame;
  169. CGRect tempRectOne = tempRect;
  170. tempRectOne.origin.y = self.view.frame.size.height;
  171. [_gPicture setFrame:tempRectOne];
  172. //动画
  173. [_gPicture setAlpha:0];
  174. [_gPicture.gViewOne setAlpha:0];
  175. [_gPicture.gImgV setAlpha:0];
  176. [UIView animateWithDuration:0.3 animations:^{
  177. [_gPicture setFrame:tempRect];
  178. [_gPicture setAlpha:1];
  179. [_gPicture.gViewOne setAlpha:1];
  180. [_gPicture.gImgV setAlpha:0.2];
  181. } completion:^(BOOL finished){}];
  182. [self cReturnLocation];
  183. //文本
  184. }else if(tempBut.tag == 4102){
  185. //发送
  186. BOOL judge = 0;
  187. for (int i = 0; i < [_gImputTxtV.text length]; i ++) {
  188. NSString *str = [_gImputTxtV.text substringWithRange:NSMakeRange(i, 1)];
  189. if(![str isEqualToString:@" "]){
  190. if(![str isEqualToString:@"\n"]){
  191. judge = 1;
  192. }
  193. }
  194. }
  195. if(judge){
  196. long int temptime = [self cNowTimestamp ];
  197. //消息发送时 立即插入数据库
  198. [self cInsertLibaryWithID:temptime andContent:_gImputTxtV.text andType:1 andFileinfo:0];
  199. }else{
  200. }
  201. [self.gCellHeightArr removeAllObjects];
  202. [_gProcessTV reloadData];
  203. _gImputTxtV.text = nil;
  204. }
  205. [self cMessageSend:40];
  206. [_gProcessTV setContentOffset:CGPointMake(0, 0)];
  207. }
  208. //图片发送
  209. - (void)gCancel:(id)sender{
  210. CGRect tempRect = _gPicture.gViewOne.frame;
  211. tempRect.origin.y = _gPicture.frame.size.height;
  212. //动画
  213. [UIView animateWithDuration:0.35 animations:^{
  214. [_gPicture.gViewOne setFrame:tempRect];
  215. [_gPicture.gViewOne setAlpha:0];
  216. [_gPicture.gImgV setAlpha:0];
  217. } completion:^(BOOL finished){
  218. [_gPicture removeFromSuperview];
  219. }];
  220. }
  221. - (void)gPlot:(id)sender{
  222. NSInteger tag = [sender tag];
  223. CGFloat height = [UIScreen mainScreen].bounds.size.height;
  224. UIView* subview = (UIView*)[self.view viewWithTag:135];
  225. CGRect rect = subview.frame;
  226. rect.origin.y = 1.0*height;
  227. [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
  228. _gPicture.alpha = 0.0;
  229. subview.frame = rect;
  230. } completion:^(BOOL finished) {
  231. if (finished) {
  232. [_gPicture removeFromSuperview];
  233. if (tag == 13) {//拍照
  234. [self presentImageViewControllerWithCameraAvailable:1];
  235. } else if (tag == 15) {//我的标绘
  236. } else {//手机相册
  237. [self presentImageViewControllerWithCameraAvailable:0];
  238. }
  239. }
  240. }];
  241. }
  242. - (void)presentImageViewControllerWithCameraAvailable:(NSUInteger)isAvaiable
  243. {
  244. UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
  245. pickerController.delegate = self;
  246. if (isAvaiable == 1) {
  247. if (![UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
  248. UIAlertView* alertView =
  249. [[UIAlertView alloc] initWithTitle:nil
  250. message:@"设备不支持拍照"
  251. delegate:nil
  252. cancelButtonTitle:@"确定"
  253. otherButtonTitles: nil];
  254. [alertView show];
  255. return;
  256. }
  257. pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
  258. } else {
  259. pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  260. }
  261. pickerController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  262. [self presentViewController:pickerController animated:YES completion:NULL];
  263. }
  264. #pragma mark - UIImagePickerControllerDelegate
  265. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  266. {
  267. UIImage *sourceImage = (UIImage *)[info valueForKey:UIImagePickerControllerOriginalImage];
  268. if (sourceImage == nil) {
  269. NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
  270. ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *asset)
  271. {
  272. ALAssetRepresentation *representation = [asset defaultRepresentation];
  273. UIImage *originalImage = [UIImage imageWithCGImage:[representation fullResolutionImage]];
  274. NSData* data = UIImageJPEGRepresentation(originalImage, 0.8);
  275. if (data) {
  276. NSString* filePath = [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]];
  277. filePath = [filePath stringFromMD5];
  278. NSString* fileItem = [NSString stringWithFormat:@"%@_P.jpg",filePath];
  279. NSString* picPath = [self getUserMessagePictureFileSavePath];
  280. picPath = [picPath stringByAppendingPathComponent:fileItem];
  281. if (![[NSFileManager defaultManager] fileExistsAtPath:picPath]) {
  282. BOOL bSuccess = [[NSFileManager defaultManager] createFileAtPath:picPath contents:data attributes:NULL];
  283. if (bSuccess) {
  284. [self cPicPicChioce:picPath];
  285. }
  286. }
  287. } else {
  288. UIAlertView* alertView =
  289. [[UIAlertView alloc] initWithTitle:nil
  290. message:@"图片已损坏"
  291. delegate:nil
  292. cancelButtonTitle:@"确定"
  293. otherButtonTitles: nil];
  294. [alertView show];
  295. }
  296. [picker dismissViewControllerAnimated:YES completion:NULL];
  297. };
  298. ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
  299. [assetslibrary assetForURL:imageURL
  300. resultBlock:resultblock
  301. failureBlock:nil];
  302. } else {
  303. NSData* data = UIImageJPEGRepresentation(sourceImage, 0.8);
  304. NSString* filePath = [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]];
  305. filePath = [filePath stringFromMD5];
  306. NSString* fileItem = [NSString stringWithFormat:@"%@_P.jpg",filePath];
  307. NSString* picPath = [self getUserMessagePictureFileSavePath];
  308. picPath = [picPath stringByAppendingPathComponent:fileItem];
  309. if (![[NSFileManager defaultManager] fileExistsAtPath:picPath]) {
  310. BOOL bSuccess = [[NSFileManager defaultManager] createFileAtPath:picPath contents:data attributes:NULL];
  311. if (bSuccess) {
  312. [self cPicPicChioce:picPath];
  313. }
  314. }
  315. [picker dismissViewControllerAnimated:YES completion:NULL];
  316. }
  317. }
  318. -(void)cPicPicChioce:(NSString *)picPath{
  319. if(picPath){
  320. [self cMessageTableView];
  321. long int temptime = [self cNowTimestamp];
  322. //消息发送时 立即插入数据库
  323. [self cInsertLibaryWithID:temptime andContent:picPath andType:2 andFileinfo:0];
  324. [_gProcessTV reloadData];
  325. }
  326. }
  327. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  328. {
  329. [picker dismissViewControllerAnimated:YES completion:NULL];
  330. }
  331. //标绘图片1
  332. -(void)didEndCell:(NSInteger)mid path:(NSString*)path controller:(UIViewController *)VC
  333. {
  334. if (path.length != 0) {
  335. //消息中心,选择图片复制
  336. UIImage *sourceImage = (UIImage *)[UIImage imageWithContentsOfFile:path];
  337. NSData* data = UIImageJPEGRepresentation(sourceImage, 0.8);
  338. NSString* filePath = [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]];
  339. filePath = [filePath stringFromMD5];
  340. NSString* fileItem = [NSString stringWithFormat:@"%@_P.jpg",filePath];
  341. NSString* picPath = [self getUserMessagePictureFileSavePath];
  342. picPath = [picPath stringByAppendingPathComponent:fileItem];
  343. if (![[NSFileManager defaultManager] fileExistsAtPath:picPath]) {
  344. BOOL bSuccess = [[NSFileManager defaultManager] createFileAtPath:picPath contents:data attributes:NULL];
  345. if (bSuccess) {
  346. if(picPath){
  347. long int temptime = [self cNowTimestamp];
  348. //消息发送时 立即插入数据库
  349. [self cInsertLibaryWithID:temptime andContent:picPath andType:2 andFileinfo:0];
  350. [_gProcessTV reloadData];
  351. }
  352. }
  353. }
  354. }
  355. }
  356. //语音
  357. //录音被取消
  358. - (void)gCancelVoice:(id)sender{
  359. CGRect tempRect = _gVoice.gViewOne.frame;
  360. tempRect.origin.y = _gVoice.frame.size.height;
  361. [UIView animateWithDuration:0.35 animations:^{
  362. [_gVoice.gViewOne setFrame:tempRect];
  363. [_gVoice.gViewOne setAlpha:0];
  364. [_gVoice.gImgV setAlpha:0];
  365. } completion:^(BOOL finished){
  366. [_gVoice removeFromSuperview];
  367. }];
  368. }
  369. //录音开始
  370. - (void)gVoiceDown:(id)sender{
  371. if (![AudioRecord hasMicphone]) {
  372. UIAlertView* alertView =
  373. [[UIAlertView alloc] initWithTitle:nil
  374. message:@"设备不支持录音"
  375. delegate:nil
  376. cancelButtonTitle:@"确定"
  377. otherButtonTitles: nil];
  378. [alertView show];
  379. return;
  380. }
  381. if ([AudioRecord isMuted]) {
  382. UIAlertView* alertView =
  383. [[UIAlertView alloc] initWithTitle:nil
  384. message:@"设备处于静音状态,请调高音量"
  385. delegate:nil
  386. cancelButtonTitle:@"确定"
  387. otherButtonTitles: nil];
  388. [alertView show];
  389. return;
  390. }
  391. if ([[self fetchSystemVersion] floatValue] >= 7.0) {
  392. //麦克风授权
  393. [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
  394. if (granted) {
  395. NSString* filePath = [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]];
  396. filePath = [filePath stringFromMD5];
  397. NSString* fileItem = [NSString stringWithFormat:@"%@_A.caf",filePath];
  398. NSString* audioPath = [self getUserMessageAudioFileSavePath];
  399. audioPath = [audioPath stringByAppendingPathComponent:fileItem];
  400. if(!self.mAudioRecord){
  401. self.mAudioRecord = [[AudioRecord alloc] init];
  402. }
  403. [self.mAudioRecord startRecordWithPath:audioPath];
  404. } else {
  405. UIAlertView* alertView =
  406. [[UIAlertView alloc] initWithTitle:nil
  407. message:@"用户不允许使用麦克风"
  408. delegate:nil
  409. cancelButtonTitle:@"确定"
  410. otherButtonTitles: nil];
  411. [alertView show];
  412. return;
  413. }
  414. }];
  415. } else {
  416. NSString* filePath = [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]];
  417. filePath = [filePath stringFromMD5];
  418. NSString* fileItem = [NSString stringWithFormat:@"%@_A.caf",filePath];
  419. NSString* audioPath = [self getUserMessageAudioFileSavePath];
  420. audioPath = [audioPath stringByAppendingPathComponent:fileItem];
  421. if(!self.mAudioRecord){
  422. self.mAudioRecord = [[AudioRecord alloc] init];
  423. }
  424. [self.mAudioRecord startRecordWithPath:audioPath];
  425. }
  426. }
  427. //录音结束
  428. - (void)gVoiceInside:(id)sender{
  429. [self.mAudioRecord stopRecord];
  430. CGFloat height = [UIScreen mainScreen].bounds.size.height;
  431. UIView* subview = (UIView*)[_gVoice.gViewOne viewWithTag:125];
  432. CGRect rect = subview.frame;
  433. rect.origin.y = 1.0*height;
  434. [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
  435. _gVoice.alpha = 0.0;
  436. subview.frame = rect;
  437. } completion:^(BOOL finished) {
  438. if (finished) {
  439. [_gVoice removeFromSuperview];
  440. }
  441. }];
  442. if (self.mAudioRecord.recordTime < 0.5f) {//录音时间太短了
  443. if ([[NSFileManager defaultManager] fileExistsAtPath:self.mAudioRecord.recordPath]) {
  444. [[NSFileManager defaultManager] removeItemAtPath:self.mAudioRecord.recordPath error:NULL];
  445. }
  446. self.mAudioRecord = nil;
  447. UIAlertView* alertView =
  448. [[UIAlertView alloc] initWithTitle:nil
  449. message:@"录音时间太短了"
  450. delegate:nil
  451. cancelButtonTitle:@"确定"
  452. otherButtonTitles: nil];
  453. [alertView show];
  454. return;
  455. } else if (self.mAudioRecord.averagePower < -40.0) {//小于-40分贝,表示没有说话
  456. if ([[NSFileManager defaultManager] fileExistsAtPath:self.mAudioRecord.recordPath]) {
  457. [[NSFileManager defaultManager] removeItemAtPath:self.mAudioRecord.recordPath error:NULL];
  458. }
  459. self.mAudioRecord = nil;
  460. UIAlertView* alertView =
  461. [[UIAlertView alloc] initWithTitle:nil
  462. message:@"你的声音太小了"
  463. delegate:nil
  464. cancelButtonTitle:@"确定"
  465. otherButtonTitles: nil];
  466. [alertView show];
  467. return;
  468. }
  469. NSString* destPath = self.mAudioRecord.recordPath;
  470. destPath = [destPath substringToIndex:destPath.length-6];
  471. //储存路径
  472. NSString* path = [NSString stringWithFormat:@"%@_%d_A.caf", destPath, (int)self.mAudioRecord.recordTime+1];
  473. if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
  474. BOOL bSuccess = [[NSFileManager defaultManager] copyItemAtPath:self.mAudioRecord.recordPath toPath:path error:NULL];
  475. if (bSuccess) {
  476. [[NSFileManager defaultManager] removeItemAtPath:self.mAudioRecord.recordPath error:NULL];
  477. }
  478. }
  479. self.mAudioRecord = nil;
  480. //.caf转换为.mp3
  481. NSString *voiPathMP3 = [self audio_PCMtoMP3:path];
  482. if(voiPathMP3){
  483. _gProcessAPlayer = [ProcessAudioPlay sharedProcessAudioPlayAction];
  484. [_gProcessAPlayer cPlayerData:voiPathMP3];
  485. _gAudioPlayer = [_gProcessAPlayer gAudioPlayer];
  486. NSInteger voiInt = _gAudioPlayer.duration;//语音时间
  487. if(voiInt < 1){
  488. voiInt = 1;
  489. }
  490. long int temptime = [self cNowTimestamp];
  491. //消息发送时 立即插入数据库
  492. [self cInsertLibaryWithID:temptime andContent:voiPathMP3 andType:3 andFileinfo:voiInt];
  493. [_gProcessTV reloadData];
  494. }
  495. }
  496. //录音被取消
  497. - (void)gVoiceOutside:(id)sender{
  498. [self.mAudioRecord cancelRecord];
  499. self.mAudioRecord = nil;
  500. CGFloat height = [UIScreen mainScreen].bounds.size.height;
  501. UIView* subview = (UIView*)[_gVoice.gViewOne viewWithTag:125];
  502. CGRect rect = subview.frame;
  503. rect.origin.y = 1.0*height;
  504. [UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
  505. _gVoice.alpha = 0.0;
  506. subview.frame = rect;
  507. } completion:^(BOOL finished) {
  508. if (finished) {
  509. [_gVoice removeFromSuperview];
  510. }
  511. }];
  512. UIAlertView* alertView =
  513. [[UIAlertView alloc] initWithTitle:nil
  514. message:@"录音被取消了"
  515. delegate:nil
  516. cancelButtonTitle:@"确定"
  517. otherButtonTitles: nil];
  518. [alertView show];
  519. }
  520. //.caf转换为.mp3
  521. -(NSString *)audio_PCMtoMP3:(NSString *)cafPath{
  522. NSString *cafFilePath = cafPath;
  523. NSMutableString *changeName = [cafFilePath mutableCopy];
  524. NSString *changePath;
  525. if([[changeName substringFromIndex:changeName.length-3] isEqualToString:@"caf"]){
  526. changePath = [changeName substringToIndex:changeName.length-3];
  527. }
  528. NSString *mp3FilePath;
  529. if(changePath){
  530. mp3FilePath = [NSString stringWithFormat:@"%@mp3",changePath];
  531. }
  532. @try {
  533. int read, write;
  534. FILE *pcm = fopen([cafFilePath cStringUsingEncoding:1], "rb"); //source 被转换的音频文件位置
  535. fseek(pcm, 4*1024, SEEK_CUR); //skip file header
  536. FILE *mp3 = fopen([mp3FilePath cStringUsingEncoding:1], "wb"); //output 输出生成的Mp3文件位置
  537. const int PCM_SIZE = 8192;
  538. const int MP3_SIZE = 8192;
  539. short int pcm_buffer[PCM_SIZE*2];
  540. unsigned char mp3_buffer[MP3_SIZE];
  541. lame_t lame = lame_init();
  542. lame_set_num_channels(lame,2);//设置1为单通道,默认为2双通道
  543. lame_set_in_samplerate(lame, 11025.0);//44100.0);//11025.0
  544. lame_set_VBR(lame, vbr_default);
  545. lame_set_brate(lame,8);
  546. lame_set_mode(lame,3);
  547. lame_set_quality(lame,2); /* 2=high 5 = medium 7=low 音质*/
  548. lame_init_params(lame);
  549. do {
  550. read = fread(pcm_buffer, 2*sizeof(short int), PCM_SIZE, pcm);
  551. if (read == 0)
  552. write = lame_encode_flush(lame, mp3_buffer, MP3_SIZE);
  553. else
  554. write = lame_encode_buffer_interleaved(lame, pcm_buffer, read, mp3_buffer, MP3_SIZE);
  555. fwrite(mp3_buffer, write, 1, mp3);
  556. } while (read != 0);
  557. lame_close(lame);
  558. fclose(mp3);
  559. fclose(pcm);
  560. }
  561. @catch (NSException *exception) {
  562. }
  563. @finally {
  564. //若转换成功, 删除caf文件
  565. NSFileManager* fileManager=[NSFileManager defaultManager];
  566. if([fileManager contentsAtPath:mp3FilePath]){
  567. [fileManager removeItemAtPath:cafFilePath error:nil];
  568. }
  569. }
  570. return mp3FilePath;
  571. }
  572. //消息发送时 立即插入数据库
  573. -(void)cInsertLibaryWithID:(long int)theID andContent:(NSString *)theContent andType:(NSInteger)theType andFileinfo:(NSInteger)theFileinfo{
  574. NSString *groupID = @"0";
  575. NSString *groupName = @"";
  576. NSString *sendName = @"";
  577. if([_titleLab.text isEqualToString:@"张三(收)"]){
  578. sendName = @"张三";
  579. }else{
  580. sendName = @"李四";
  581. }
  582. NSString *myID = _gMyObjectID;
  583. NSMutableDictionary *messageSend = [[NSMutableDictionary alloc] init];
  584. [messageSend setObject:[NSNumber numberWithLong:theID] forKey:@"id"];
  585. [messageSend setObject:theContent forKey:@"content"];
  586. [messageSend setObject:[NSNumber numberWithInt:theType] forKey:@"type"];
  587. [messageSend setObject:[NSNumber numberWithLong:theID] forKey:@"addtime"];
  588. [messageSend setObject:@"" forKey:@"fileinfo"];
  589. [messageSend setObject:_gObjectID forKey:@"receive_uid"];
  590. [messageSend setObject:[NSNumber numberWithInt:0] forKey:@"rectime"];
  591. [messageSend setObject:[NSString stringWithFormat:@"%@",myID] forKey:@"send_uid"];
  592. [messageSend setObject:sendName forKey:@"send_uname"];
  593. [messageSend setObject:[NSNumber numberWithInt:1] forKey:@"send"];//2 请求,0 失败,1 成功
  594. [messageSend setObject:[NSNumber numberWithInt:theFileinfo] forKey:@"fileinfo"];
  595. [messageSend setObject:groupID forKey:@"groupid"];
  596. [messageSend setObject:groupName forKey:@"groupname"];
  597. //插入数据库 默认为未发送成功
  598. [self cSendTalkDatabaseInsertInto:messageSend];
  599. messageSend = nil;
  600. }
  601. //消息发送时 数据库插入 用户交谈
  602. -(void)cSendTalkDatabaseInsertInto:(NSDictionary *)talkDict{
  603. //特殊字符转换——
  604. NSString *strContent = [talkDict objectForKey:@"content"];
  605. if(strContent == nil || [strContent isEqualToString:@""]){
  606. strContent = [talkDict objectForKey:@"content"];
  607. }
  608. //现在表中查询有没有相同的元素,如果有,做修改操作
  609. NSString *sqlCodeOne = [NSString stringWithFormat:@"select * from UserTalk where Tid = %lld",[[talkDict objectForKey:@"id"] longLongValue]];
  610. PTDBManage* manager = [[PTDBManage alloc] init];
  611. FMResultSet *rs = [[manager startDB] executeQuery:sqlCodeOne];
  612. BOOL result = NO;
  613. if([rs next])
  614. {
  615. result = YES;
  616. }
  617. [rs close];
  618. [manager endDB];
  619. if(!result){
  620. //3.插入
  621. NSString *sqlCode = [NSString stringWithFormat:@"INSERT INTO UserTalk (Tid,Ttype,Tsend_uid,Tsend_uname,Treceive_uid,Tcontent,Taddtime,Trectime,Tsend,TfileInfo,Fuserid,Fobjectid,UGroupId,UGroupName) VALUES (%d,%d,'%@','%@','%@','%@',%d,%d,%d,%d,'%@','%@','%@','%@')",
  622. [[talkDict objectForKey:@"id"] intValue],
  623. [[talkDict objectForKey:@"type"] intValue],
  624. [talkDict objectForKey:@"send_uid"],
  625. [talkDict objectForKey:@"send_uname"],
  626. [talkDict objectForKey:@"receive_uid"],
  627. strContent,
  628. [[talkDict objectForKey:@"addtime"] intValue],
  629. [[talkDict objectForKey:@"rectime"] intValue],
  630. [[talkDict objectForKey:@"send"] intValue],
  631. [[talkDict objectForKey:@"fileinfo"] intValue],
  632. _gUserid,
  633. _gObjectID,
  634. [talkDict objectForKey:@"groupid"],
  635. [talkDict objectForKey:@"groupname"]
  636. ];
  637. //插入数据使用OC中的类型 text对应为NSString integer对应为NSNumber的整形
  638. manager = [[PTDBManage alloc] init];
  639. BOOL success = [[manager startDB] executeUpdate:sqlCode];
  640. if(success){
  641. NSLog(@"---------insert DB sucess-----------");
  642. }else{
  643. NSLog(@"---------insert DB faile------------");
  644. }
  645. [manager endDB];
  646. }
  647. }
  648. -(void)cReturnDown{
  649. UIView *tempV = (UIView *)[self.view viewWithTag:6500];
  650. [UIView animateWithDuration:0.2 animations:^{
  651. [tempV setFrame:CGRectMake(0, self.view.frame.size.height-150, self.view.frame.size.width, 150)];
  652. } completion:^(BOOL finished){}];
  653. }
  654. //获得当前时间
  655. -(NSString *)cAcquireNowTime:(NSString *)timestamp{
  656. NSDate *timeData = [NSDate dateWithTimeIntervalSince1970:[timestamp intValue]];
  657. NSDateFormatter *dateFormatter =[[NSDateFormatter alloc] init];
  658. [dateFormatter setDateFormat:@"yyyy年M月d日 HH:mm"];
  659. NSString *strTime = [dateFormatter stringFromDate:timeData];
  660. [dateFormatter setDateFormat:@"HH:mm"];
  661. NSString *strTimeTwo = [dateFormatter stringFromDate:timeData];
  662. [dateFormatter setDateFormat:@"yyyy"];
  663. NSString *strYear = [dateFormatter stringFromDate:timeData];
  664. [dateFormatter setDateFormat:@"M"];
  665. NSString *strMonth = [dateFormatter stringFromDate:timeData];
  666. [dateFormatter setDateFormat:@"d"];
  667. NSString *strDay = [dateFormatter stringFromDate:timeData];
  668. if([timestamp isEqualToString:@""]){
  669. return @"";
  670. }else{
  671. if(![strDay isEqualToString:[self cNowTimestamp:@"d"]]){
  672. return strTime;
  673. }else if([strYear isEqualToString:[self cNowTimestamp:@"yyyy"]] && [strMonth isEqualToString:[self cNowTimestamp:@"M"]] && [strDay isEqualToString:[self cNowTimestamp:@"d"]]){
  674. return strTimeTwo;
  675. }
  676. }
  677. return strTime;
  678. }
  679. //当前时间的时间戳_日
  680. -(NSString *)cNowTimestamp:(NSString *)theMark{
  681. long int timeSp = [self cNowTimestamp];
  682. NSDate *timeData = [NSDate dateWithTimeIntervalSince1970:timeSp];
  683. NSDateFormatter *dateFormatter =[[NSDateFormatter alloc] init];
  684. [dateFormatter setDateFormat:theMark];
  685. NSString *strTime = [dateFormatter stringFromDate:timeData];
  686. return strTime;
  687. }
  688. //Cell自适应高度
  689. -(CGRect)cAdaptCellHeight:(NSString *)theStr{
  690. NSString *desContent = theStr; //获取文本内容
  691. CGRect orgRect = CGRectMake(0, 0, 0, 0); //获取原始UITextView的frame
  692. CGSize size = [desContent sizeWithFont:[UIFont systemFontOfSize:15] constrainedToSize:CGSizeMake(230-20, 2000) lineBreakMode:NSLineBreakByWordWrapping];
  693. orgRect.size.height = size.height;
  694. return orgRect;
  695. }
  696. //发送消息块 移动
  697. -(void)cMoveLocation{
  698. CGRect sendRect = _gSendV.frame;
  699. sendRect.origin.y = self.view.frame.size.height - _gKeyBoardH-_gSendV.frame.size.height;
  700. CGRect tvrect = self.gTVrect;
  701. tvrect.size.height = tvrect.size.height - _gKeyBoardH;
  702. [UIView animateWithDuration:0.25 animations:^{
  703. [_gSendV setFrame:sendRect];
  704. [_gProcessTV setFrame:tvrect];
  705. } completion:^(BOOL finished){}];
  706. [_gProcessTV setContentOffset:CGPointMake(0, 0) animated:YES];
  707. }
  708. //发送消息块 归位
  709. -(void)cReturnLocation{
  710. CGRect tempRect = _gSendV.frame;
  711. tempRect.origin.y = self.view.frame.size.height-_gSendV.frame.size.height;
  712. [self.view endEditing:YES];
  713. [_gProcessTV setFrame:self.gTVrect];
  714. [_gProcessTV reloadData];
  715. [UIView animateWithDuration:0.25 animations:^{
  716. [_gSendV setFrame:tempRect];
  717. } completion:^(BOOL finished){
  718. _gKeyBoardH = 0;
  719. }];
  720. }
  721. //当键盘出现或改变时调用
  722. - (void)keyboardWillShow:(NSNotification *)aNotification{
  723. NSDictionary *userInfo = [aNotification userInfo];
  724. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  725. CGRect keyboardRect = [aValue CGRectValue];
  726. int height = keyboardRect.size.height;
  727. _gKeyBoardH = height;
  728. [self cMoveLocation];
  729. }
  730. //当键退出时调用
  731. - (void)keyboardWillHide:(NSNotification *)aNotification{
  732. [self cReturnLocation];
  733. }
  734. #pragma mark UITextViewDelegate
  735. - (void)textViewDidChange:(UITextView *)textView{
  736. if (textView.tag == 4200) {
  737. CGSize textSize = textView.contentSize;
  738. textSize.height = textSize.height + 8;
  739. [textView setContentSize:textSize];
  740. [self cMessageSend:textView.contentSize.height];
  741. }
  742. }
  743. #pragma mark UITableViewDataSource
  744. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  745. [self.gCellHeightArr removeAllObjects];
  746. return 1;
  747. }
  748. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  749. //从数据库获取数据
  750. [self cTalkTVRowAction];
  751. NSInteger returnRow;
  752. returnRow = [self.gMessageInfo count];
  753. return returnRow;
  754. }
  755. //数据准备
  756. -(void)cTalkTVRowAction{
  757. NSMutableArray *sqlMarr = [[NSMutableArray alloc] init];
  758. FMResultSet *rs;
  759. NSString *myID = _gMyObjectID;
  760. //sql语句
  761. NSString *sqlCode = [NSString stringWithFormat:@"select * from UserTalk where (Tsend_uid='%@' and Treceive_uid='%@' and Fuserid = '%@' and UGroupId='%@') or (Tsend_uid='%@' and Treceive_uid='%@' and Fuserid = '%@' and UGroupId='%@') order by Taddtime Desc",myID,_gObjectID,_gUserid,@"0",_gObjectID,myID,_gUserid,@"0"];
  762. PTDBManage* manager = [[PTDBManage alloc] init];
  763. rs = [[manager startDB] executeQuery:sqlCode];
  764. //判断结果集中是否有数据,如果有则取出数据
  765. while ([rs next]) {
  766. NSMutableDictionary *tempdict = [[NSMutableDictionary alloc] init];
  767. [tempdict setObject:[NSString stringWithFormat:@"%d",[rs intForColumn:@"Tid"]] forKey:@"id"];
  768. [tempdict setObject:[NSString stringWithFormat:@"%d",[rs intForColumn:@"Ttype"]] forKey:@"type"];
  769. [tempdict setObject:[rs stringForColumn:@"Tsend_uid"] forKey:@"send_uid"];
  770. [tempdict setObject:[rs stringForColumn:@"Tsend_uname"] forKey:@"send_uname"];
  771. [tempdict setObject:[rs stringForColumn:@"Treceive_uid"] forKey:@"receive_uid"];
  772. [tempdict setObject:[NSString stringWithFormat:@"%d",[rs intForColumn:@"Fuserid"]] forKey:@"userid"];
  773. //转换为特殊字符
  774. NSString *strContent = [rs stringForColumn:@"Tcontent"];
  775. [tempdict setObject:strContent forKey:@"content"];
  776. [tempdict setObject:[NSString stringWithFormat:@"%d",[rs intForColumn:@"Taddtime"]] forKey:@"addtime"];
  777. [tempdict setObject:[NSString stringWithFormat:@"%d",[rs intForColumn:@"Trectime"]] forKey:@"rectime"];
  778. [tempdict setObject:[NSString stringWithFormat:@"%d",[rs intForColumn:@"Tsend"]] forKey:@"send"];
  779. [tempdict setObject:[NSString stringWithFormat:@"%d",[rs intForColumn:@"TfileInfo"]] forKey:@"fileinfo"];
  780. [tempdict setObject:[NSString stringWithFormat:@"%d",[[rs stringForColumn:@"UGroupId"] integerValue]] forKey:@"groupid"];
  781. [tempdict setObject:[rs stringForColumn:@"UGroupName"] forKey:@"groupname"];
  782. //将查询到的数据放入数组中。
  783. [sqlMarr addObject:tempdict];
  784. }
  785. [rs close];
  786. [manager endDB];
  787. //点击查看更多
  788. NSInteger tempInt = 15*_leftPageNum;
  789. if([sqlMarr count] > tempInt ){
  790. self.gMessageInfo = [[sqlMarr subarrayWithRange:NSMakeRange(0, tempInt)] mutableCopy];
  791. //点击加载更多
  792. [self startLoadingAction];
  793. }else{
  794. //加载完成
  795. self.gMessageInfo = sqlMarr;
  796. [self stopLoadingAction];
  797. }
  798. if(self.gMessageInfo.count < 15){
  799. [_gProcessTV.tableFooterView setHidden:YES];
  800. }else{
  801. [_gProcessTV.tableFooterView setHidden:NO];
  802. }
  803. //5分钟内时间清空
  804. for (int i = self.gMessageInfo.count-1; i >= 0; i --) {
  805. NSDictionary *idict = [self.gMessageInfo objectAtIndex:i];
  806. NSString *iaddtime = [idict objectForKey:@"addtime"];
  807. NSInteger oldtime = [iaddtime integerValue];
  808. for (int j = i-1 ; j >= 0 ; j --) {
  809. NSDictionary *jdict = [self.gMessageInfo objectAtIndex:j];
  810. NSString *jaddtime = [jdict objectForKey:@"addtime"];
  811. NSInteger newtime = [jaddtime integerValue];
  812. if((oldtime-newtime)>300 || (newtime-oldtime)>300){
  813. }else{
  814. [jdict setValue:@"" forKey:@"addtime"];
  815. }
  816. }
  817. }
  818. }
  819. //TV
  820. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  821. static NSString *cellIdentifier=@"GroupMessageCell";
  822. GroupMessageCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  823. [cell releaseAction];
  824. if (!cell) {
  825. cell = (GroupMessageCell*)[[[NSBundle mainBundle] loadNibNamed:@"GroupMessageCell" owner:nil options:nil] objectAtIndex:0];
  826. cell.backgroundColor=[UIColor clearColor];
  827. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  828. }
  829. float cellHeight = [tableView rectForRowAtIndexPath:indexPath].size.height;
  830. NSDictionary *cellDict = (NSDictionary *)[self.gMessageInfo objectAtIndex:indexPath.row];
  831. if(cellDict){
  832. BOOL result = NO;
  833. if([[cellDict objectForKey:@"send_uid"] isEqualToString:_gMyObjectID]){
  834. result = YES;
  835. }
  836. //文本
  837. if([[cellDict objectForKey:@"type"] intValue] == 1){
  838. [cell cProcessMessageTime:[self cAcquireNowTime:[cellDict objectForKey:@"addtime"] ] andInfo:[cellDict objectForKey:@"content"] andIsMy:result andInfoHeight:cellHeight andSend:[cellDict objectForKey:@"send"] andTalkID:_gObjectID andSendName:[cellDict objectForKey:@"send_uname"]];
  839. //图片
  840. }else if ([[cellDict objectForKey:@"type"] intValue] == 2){
  841. [cell cProcessMessageTime:[self cAcquireNowTime:[cellDict objectForKey:@"addtime"] ] andPicture:[cellDict objectForKey:@"content"] andIsMy:result andInfoHeight:cellHeight andSend:[cellDict objectForKey:@"send"] andTalkID:_gObjectID andSendName:[cellDict objectForKey:@"send_uname"]];
  842. //语音
  843. }else if([[cellDict objectForKey:@"type"] intValue] == 3){
  844. [cell cProcessMessageTime:[self cAcquireNowTime:[cellDict objectForKey:@"addtime"] ] andVoicePath:[cellDict objectForKey:@"content"] andIsMy:result andInfoHeight:cellHeight andSend:[cellDict objectForKey:@"send"] andTalkID:_gObjectID andSendName:[cellDict objectForKey:@"send_uname"] andFileInfo:[[cellDict objectForKey:@"fileinfo"] intValue]];
  845. }else{
  846. [cell hidnViewAction];
  847. }
  848. }
  849. [cell setTransform:CGAffineTransformMakeRotation(M_PI)];
  850. return cell;
  851. }
  852. #pragma mark UITableViewDelegate
  853. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  854. float returnHeight = 44;
  855. if([self.gMessageInfo count]<15){
  856. NSDictionary *cellDict = (NSDictionary *)[self.gMessageInfo objectAtIndex:indexPath.row];
  857. if(cellDict){
  858. if ([[cellDict objectForKey:@"type"] intValue] == 2){
  859. UIImage *teImg = [UIImage imageWithContentsOfFile:[cellDict objectForKey:@"content"]];
  860. UIImage *tempImg = teImg;
  861. if(tempImg.size.height > 100){
  862. returnHeight = 100+50;
  863. }else{
  864. returnHeight = tempImg.size.height;
  865. if(returnHeight<50){
  866. returnHeight = 50+50;
  867. }else{
  868. returnHeight = returnHeight +50;
  869. }
  870. }
  871. //语音
  872. }else if([[cellDict objectForKey:@"type"] intValue] == 3){
  873. returnHeight = 20+50;
  874. }//文本
  875. else{
  876. NSString *tempStr = [cellDict objectForKey:@"content"];
  877. //原因是从XML中读取出来的"\n",系统认为是字符串,会默认转换为"\\n",所以当显示的时候就是字符串了,要想显示换行,需要自己手动将"\\n"转换为"\n",这样才能换行.
  878. NSString*b =[tempStr stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
  879. CGRect tempFrame = [self cAdaptCellHeight:b];
  880. returnHeight = tempFrame.size.height+50;
  881. }
  882. }else{
  883. }
  884. [self.gCellHeightArr addObject:[NSNumber numberWithFloat:returnHeight]];
  885. }else{
  886. NSDictionary *cellDict = (NSDictionary *)[self.gMessageInfo objectAtIndex:indexPath.row];
  887. if(cellDict){
  888. if ([[cellDict objectForKey:@"type"] intValue] == 2){
  889. UIImage *teImg = [UIImage imageWithContentsOfFile:[cellDict objectForKey:@"content"]];
  890. UIImage *tempImg = teImg;
  891. if(tempImg.size.height > 100){
  892. returnHeight = 100+50;
  893. }else{
  894. returnHeight = tempImg.size.height;
  895. if(returnHeight<50){
  896. returnHeight = 50+50;
  897. }else{
  898. returnHeight = returnHeight +50;
  899. }
  900. }
  901. //语音
  902. }else if([[cellDict objectForKey:@"type"] intValue] == 3){
  903. returnHeight = 20+50;
  904. //文本
  905. }else{
  906. NSString *tempStr = [cellDict objectForKey:@"content"];
  907. NSString*b =[tempStr stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
  908. CGRect tempFrame = [self cAdaptCellHeight:b];
  909. returnHeight = tempFrame.size.height+50;
  910. }
  911. }else{
  912. }
  913. [self.gCellHeightArr addObject:[NSNumber numberWithFloat:returnHeight]];
  914. }
  915. returnHeight = returnHeight + 15;
  916. return returnHeight;
  917. }
  918. //正在加载
  919. - (IBAction)loadingMoreAction:(id)sender {
  920. [_tapLoadBut setTitle:@"点击加载更多" forState:UIControlStateNormal];
  921. [_tapLoadBut setHidden:YES];
  922. [_loadingView setHidden:NO];
  923. _leftPageNum = _leftPageNum + 1;
  924. [_gProcessTV reloadData];
  925. }
  926. //点击加载更多
  927. -(void)startLoadingAction{
  928. [_tapLoadBut setTitle:@"点击加载更多" forState:UIControlStateNormal];
  929. [_tapLoadBut setUserInteractionEnabled:YES];
  930. [_tapLoadBut setHidden:NO];
  931. [_loadingView setHidden:YES];
  932. }
  933. //加载完成
  934. -(void)stopLoadingAction{
  935. [_tapLoadBut setTitle:@"加载完成" forState:UIControlStateNormal];
  936. [_tapLoadBut setUserInteractionEnabled:NO];
  937. [_tapLoadBut setHidden:NO];
  938. [_loadingView setHidden:YES];
  939. }
  940. //判断字符串不全为空
  941. -(BOOL)judgeStringIsNull:(NSString *)string{
  942. BOOL result = NO;
  943. if(string != nil && string.length > 0){
  944. for (int i = 0; i < string.length; i ++) {
  945. NSString *subStr = [string substringWithRange:NSMakeRange(i, 1)];
  946. if(![subStr isEqualToString:@" "] && ![subStr isEqualToString:@""]){
  947. result = YES;
  948. }
  949. }
  950. }
  951. return result;
  952. }
  953. //当前时间的时间戳
  954. -(long int)cNowTimestamp{
  955. NSDate *newDate = [NSDate date];
  956. long int timeSp = (long)[newDate timeIntervalSince1970];
  957. return timeSp;
  958. }
  959. - (NSString*)getUserMessagePictureFileSavePath{
  960. NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Message"];
  961. NSString *filePath = [path stringByAppendingPathComponent:@"Pictures"];
  962. if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
  963. [[NSFileManager defaultManager] createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  964. }
  965. return filePath;
  966. }
  967. - (NSString*)getUserMessageAudioFileSavePath{
  968. NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Message"];
  969. NSString *filePath = [path stringByAppendingPathComponent:@"Audios"];
  970. if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
  971. [[NSFileManager defaultManager] createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil];
  972. }
  973. return filePath;
  974. }
  975. - (NSString *)fetchSystemVersion{
  976. return [[UIDevice currentDevice] systemVersion];
  977. }
  978. @end


示图:









声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/652308
推荐阅读
相关标签
  

闽ICP备14008679号