| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483 |
- //
- // LogAddViewController.m
- // IBOSSmini
- //
- // Created by guan hong hou on 2017/5/9.
- // Copyright © 2017年 elongtian. All rights reserved.
- //
- #define logTextFont [UIFont systemFontOfSize:14]
- #import "LogAddViewController.h"
- #import "DateFormat.h"
- #import "LogShareVC.h"
- #import "LogCommentVC.h"
- #import "LogNewCollectionViewCell.h"
- #import "MapViewController.h"
- #import <MobileCoreServices/MobileCoreServices.h>
- #import "DKAudioPlayerHelper.h"
- #import "LeslieAsyncImageDownloader.h"
- @interface LogAddViewController ()
- @end
- @implementation LogAddViewController{
- UITabBar* bar;
- UIView * contentView;
- UIView *vPositionView;
- UIScrollView *scroll;
- }
- @synthesize shareArr=_shareArr;
- @synthesize commentArr=_commentArr;
- #pragma mark - 公共函数
- /**
- viewDidLoad函数
- */
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.navigationItem.title=@"新增日志";
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setBackgroundImage:[UIImage imageNamed:@"icon_back.png"]
- forState:UIControlStateNormal];
- [button addTarget:self action:@selector(goBack)
- forControlEvents:UIControlEventTouchUpInside];
- button.frame = CGRectMake(0, 0, 15, 18);
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
- self.navigationItem.leftBarButtonItem = menuButton;
- [self initUI];
- _allowsSendVoice = YES;
- self.delegate = self;
- self.dataSource = self;
- _sDate= [DateFormat getCurrentDateTime];
- [_btnDate setTitle:[DateFormat dateFormatSplit:_sDate]forState:UIControlStateNormal];
- }
- /**
- 安全区视图发生变化
- */
- -(void)viewSafeAreaInsetsDidChange{
-
- scroll.frame = CGRectMake(0, 0, SCREENWIDTH, self.view.safeAreaLayoutGuide.layoutFrame.size.height- 45.0);
- CGRect inputFrame = CGRectMake(0.0f,
- self.view.safeAreaLayoutGuide.layoutFrame.size.height - 45.0,
- self.view.safeAreaLayoutGuide.layoutFrame.size.width,
- 45.0);
- _inputView.frame = inputFrame;
- [super viewSafeAreaInsetsDidChange];
- }
- //获得DKVoiceRecordHUD
- - (DKVoiceRecordHUD *)voiceRecordHUD {
- if (!_voiceRecordHUD) {
- _voiceRecordHUD = [[DKVoiceRecordHUD alloc] initWithFrame:CGRectMake(0, 0, 140, 140)];
- }
- return _voiceRecordHUD;
- }
- //获得DKVoiceRecordHelper
- - (DKVoiceRecordHelper *)voiceRecordHelper {
- if (!_voiceRecordHelper) {
- _isMaxTimeStop = NO;
-
- WEAKSELF
- _voiceRecordHelper = [[DKVoiceRecordHelper alloc] init];
- _voiceRecordHelper.maxTimeStopRecorderCompletion = ^{
- UIButton *holdDown = weakSelf.inputView.holdDownButton;
- holdDown.selected = NO;
- holdDown.highlighted = NO;
- weakSelf.isMaxTimeStop = YES;
-
- [weakSelf finishRecorded];
- };
- _voiceRecordHelper.peakPowerForChannel = ^(float peakPowerForChannel) {
- weakSelf.voiceRecordHUD.peakPower = peakPowerForChannel;
- };
- _voiceRecordHelper.maxRecordTime = kVoiceRecorderTotalTime;
- }
- return _voiceRecordHelper;
- }
- //手机屏幕方向方法
- #if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0
- - (NSUInteger)supportedInterfaceOrientations
- #else
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations
- #endif
- {
- return UIInterfaceOrientationMaskPortrait;
- }
- - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
- return UIInterfaceOrientationPortrait;
- }
- //相册数组属性
- - (NSMutableArray *)assets{
- if (!_assets) {
- _assets = [NSMutableArray array];
- }
- return _assets;
- }
- //图片路径数组
- - (NSMutableArray *)imagePaths{
- if (!_imagePaths) {
- _imagePaths = [NSMutableArray array];
- }
- return _imagePaths;
- }
- //声音路径数组
- - (NSMutableArray *)voicePaths{
- if (!_voicePaths) {
- _voicePaths = [NSMutableArray array];
- }
- return _voicePaths;
- }
- //声音上传路径数组
- - (NSMutableArray *)voiceUploadPaths{
- if (!_voiceUploadPaths) {
- _voiceUploadPaths = [NSMutableArray array];
- }
- return _voiceUploadPaths;
- }
- //声音上传时间数组
- -(NSMutableArray *)voiceUploadTimes{
- if (!_voiceUploadTimes) {
- _voiceUploadTimes = [NSMutableArray array];
- }
- return _voiceUploadTimes;
- }
- //图片本地路径数组
- -(NSMutableArray *)imageLocalPaths{
- if (!_imageLocalPaths) {
- _imageLocalPaths = [NSMutableArray array];
- }
- return _imageLocalPaths;
-
- }
- // 播放语音方法
- - (void)multiMediaMessageDidSelectedOnMessage:(id<DKMessageModel>)message atIndexPath:(NSIndexPath *)indexPath onMessageTableViewCell:(DKUITableViewCell *)messageTableViewCell {
- UIViewController *disPlayViewController;
- switch (message.messageMediaType) {
-
- case DKBubbleMessageMediaTypeVoice: {
- message.isRead = YES;
- messageTableViewCell.messageBubbleView.voiceUnreadDotImageView.hidden = YES;
-
- [[DKAudioPlayerHelper shareInstance] setDelegate:(id<NSFileManagerDelegate>)self];
- if (_currentSelectedCell) {
- [_currentSelectedCell.messageBubbleView.animationVoiceImageView stopAnimating];
- }
- if (_currentSelectedCell == messageTableViewCell) {
- [messageTableViewCell.messageBubbleView.animationVoiceImageView stopAnimating];
- [[DKAudioPlayerHelper shareInstance] stopAudio];
- self.currentSelectedCell = nil;
- } else {
- self.currentSelectedCell = messageTableViewCell;
- [messageTableViewCell.messageBubbleView.animationVoiceImageView startAnimating];
- [[DKAudioPlayerHelper shareInstance] managerAudioWithFileName:message.voicePath toPlay:YES];
- }
- break;
- }
- default:
- break;
- }
- if (disPlayViewController) {
- [self.navigationController pushViewController:disPlayViewController animated:YES];
- }
- }
- //停止播放语音方法
- - (void)didAudioPlayerStopPlay:(AVAudioPlayer *)audioPlayer {
- if (!_currentSelectedCell) {
- return;
- }
- [_currentSelectedCell.messageBubbleView.animationVoiceImageView stopAnimating];
- self.currentSelectedCell = nil;
- }
- /**
- * 发送语音消息的回调方法
- *
- * @param voicePath 目标语音本地路径
- * @param voiceDuration 目标语音时长
- * @param sender 发送者的名字
- * @param date 发送时间
- */
- - (void)didSendVoice:(NSString *)voicePath voiceDuration:(NSString *)voiceDuration fromSender:(NSString *)sender onDate:(NSDate *)date {
- int value=ceilf([voiceDuration floatValue]);
- NSString* duration=[NSString stringWithFormat:@"%d",value ] ;
- DKMessage *voiceMessage = [[DKMessage alloc] initWithVoicePath:voicePath voiceUrl:nil voiceDuration:duration sender:sender timestamp:date];
- [self.voicePaths addObject:voicePath];
- [self.voiceUploadTimes addObject:duration];
- [self addMessage:voiceMessage];
- CGFloat collectionheight=0;
-
- if (self.assets.count==0) {
- collectionheight=0;
- }else {
-
- collectionheight= [self getPhotoCollectionViewHeightWithPhotos:self.assets];
- }
- _collectionView.frame=CGRectMake(10,CGRectGetMaxY(_txtContent.frame)+8, Screen_Width-20, collectionheight);
- _positionImg.frame=CGRectMake(15, CGRectGetMaxY(_collectionView.frame)+15,9,12);
- _lblPosition.frame=CGRectMake(CGRectGetMaxX(_positionImg.frame)+11,CGRectGetMaxY(_collectionView.frame)+10, 350, 20);
- _btnTakePhoto.frame=CGRectMake(15, CGRectGetMaxY(_positionImg.frame)+15,80,20);
- _btnPhoto.frame=CGRectMake((Screen_Width/3)+15, CGRectGetMaxY(_positionImg.frame)+15,80,20);
- _btnPosition.frame=CGRectMake((Screen_Width/3*2)+15, CGRectGetMaxY(_positionImg.frame)+15,80,20);
- _separatorView.frame=CGRectMake(15, CGRectGetMaxY(_btnTakePhoto.frame)+15,Screen_Width-15, 1);
- _voiceImg.frame=CGRectMake(17,CGRectGetMaxY(_separatorView.frame)+18, 13, 15);
- _lblVoice.frame=CGRectMake(CGRectGetMaxX(_voiceImg.frame)+13,CGRectGetMaxY(_separatorView.frame)+15,30, 20);
- _btnRecord.frame=CGRectMake(Screen_Width-90, CGRectGetMaxY(_separatorView.frame)+18,100,20);
-
-
- _messageTV.frame=CGRectMake(CGRectGetMaxX(_lblVoice.frame)+2, CGRectGetMaxY(_separatorView.frame)+18,190, [self getSoundViewHeight:self.voicePaths]);
- // _messageTV.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- if(self.voicePaths.count>0){
- contentView.frame=CGRectMake(0, 0, Screen_Width,CGRectGetMaxY(_messageTV.frame));
-
- }
- else{
- contentView.frame=CGRectMake(0, 0, Screen_Width,CGRectGetMaxY(_btnRecord.frame));
- }
- scroll.contentSize=CGSizeMake(self.view.frame.size.width, contentView.frame.size.height+110);
-
-
- }
- // DKMessageTableViewController Delegate
- - (BOOL)shouldPreventScrollToBottomWhileUserScrolling {
- return YES;
- }
- //DKMessageTableViewController DataSource
- - (id <DKMessageModel>)messageForRowAtIndexPath:(NSIndexPath *)indexPath {
- return self.messages[indexPath.row];
- }
- // DKMessageInputView Delegate
- - (void)didChangeSendVoiceAction:(BOOL)changed {
- if (changed) {
- if (self.textViewInputViewType == DKInputViewTypeText)
- return;
- [self layoutOtherMenuViewHiden:YES];
- }
- }
- // scrollView delegate开始拖拽方法
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
- self.isUserScrolling = YES;
- UIMenuController *menu = [UIMenuController sharedMenuController];
- if (menu.isMenuVisible) {
- [menu setMenuVisible:NO animated:YES];
- }
-
- if (self.textViewInputViewType != DKInputViewTypeNormal) {
- // [self layoutOtherMenuViewHiden:YES];
- }
- }
- /*
- scrollView delegate结束拖拽方法
- */
- - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
- self.isUserScrolling = NO;
- }
- //点击位置后回调函数
- -(void)relocationData:(NSString *)name{
- self.sLocation=name;
-
- if (self.sLocation.length>0){
- _lblPosition.text=self.sLocation;
- }
- }
- // 保存完成后更新画面
- - (void)onLoadFinish:(ASIDownManager *)sender {
-
- NSDictionary *dic = [sender.mWebStr JSONValue];
-
- [self cancel];
- if (dic && [dic isKindOfClass:[NSDictionary class]]) {
- int iStatus = [[dic objectForKey:@"Status"] intValue];
- NSString *message=[dic objectForKey:@"Message"];
- self.navigationItem.rightBarButtonItem.enabled=YES;
- if (iStatus == 0) {
- [self clearSenderData];
- [self showAlertViewText:@"保存成功!"];
- }
- else if(iStatus==ActionResultStatusAuthError
- ||iStatus==ActionResultStatusNoLogin
- ||iStatus==ActionResultStatusLogined ||iStatus == ActionResultStatusLoginedInvalid){
- [self showReLoginDialog:message];
- return;
- }
- else {
-
- [self showAlertViewText:message];
- }
-
- }
- }
- // 保存失败
- - (void)onLoadFail:(ASIDownManager *)sender {
- [self cancel];
- self.navigationItem.rightBarButtonItem.enabled=YES;
- [self showAlertViewText:@"操作失败"];
- }
- //开始编辑UITextField的方法 开始编辑UITextField的方法
- -(void)textViewDidBeginEditing:(UITextView *)textView
- {
- CGRect textFrame = textView.frame;
- float textY = textFrame.origin.y+textFrame.size.height;
- float bottomY = self.view.frame.size.height-textY;
- if(bottomY>=216) //判断当前的高度是否已经有216,如果超过了就不需要再移动主界面的View高度
- {
- _preTag = -1;
- return;
- }
- _preTag = textView.tag;
- float moveY = 216-bottomY;
- _preMoveY = moveY;
-
- NSTimeInterval animationDuration = 0.30f;
- CGRect frame = self.view.frame;
- frame.origin.y -=moveY;//view的Y轴上移
- frame.size.height +=moveY; //View的高度增加
- self.view.frame = frame;
- [UIView beginAnimations:@"ResizeView" context:nil];
- [UIView setAnimationDuration:animationDuration];
- self.view.frame = frame;
- [UIView commitAnimations];//设置调整界面的动画效果
- }
- /**
- 结束编辑UITextField的方法,让原来的界面还原高度
- */
- -(void)textViewDidEndEditing:(UITextView *)textView
- {
- if(_preTag == -1) //当编辑的View不是需要移动的View
- {
- return;
- }
- float moveY ;
- NSTimeInterval animationDuration = 0.30f;
- CGRect frame = self.view.frame;
- if(_preTag == textView.tag) //当结束编辑的View的TAG是上次的就移动
- { //还原界面
- moveY = _preMoveY;
- frame.origin.y +=moveY;
- frame.size. height -=moveY;
- self.view.frame = frame;
- }
- //self.view移回原位置
- [UIView beginAnimations:@"ResizeView" context:nil];
- [UIView setAnimationDuration:animationDuration];
- self.view.frame = frame;
- [UIView commitAnimations];
- [textView resignFirstResponder];
-
-
- }
- //Table View 数据源-得到分区数
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 1;
- }
- //Table View 数据源-每个分区的行数
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.messages.count;
- }
- //Table View 数据源-获得tableviewcell
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
-
- id <DKMessageModel> message = [self.dataSource messageForRowAtIndexPath:indexPath];
-
- // 如果需要定制复杂的业务UI,那么就实现该DataSource方法
- if ([self.dataSource respondsToSelector:@selector(tableView:cellForRowAtIndexPath:targetMessage:)]) {
- UITableViewCell *tableViewCell = [self.dataSource tableView:tableView cellForRowAtIndexPath:indexPath targetMessage:message];
- return tableViewCell;
- }
-
- BOOL displayTimestamp = NO;
- static NSString *cellIdentifier = @"DKUITableViewCell";
-
- DKUITableViewCell *messageTableViewCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
-
- if (!messageTableViewCell) {
- messageTableViewCell = [[DKUITableViewCell alloc] initWithMessage:message displaysTimestamp:displayTimestamp reuseIdentifier:cellIdentifier];
- messageTableViewCell.delegate = self;
- }
-
- messageTableViewCell.indexPath = indexPath;
- [messageTableViewCell configureCellWithMessage:message displaysTimestamp:displayTimestamp];
- [messageTableViewCell setBackgroundColor:tableView.backgroundColor];
-
-
- return messageTableViewCell;
- }
- //获得tableview的高度
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- id <DKMessageModel> messageModel = [self.dataSource messageForRowAtIndexPath:indexPath];
-
- CGFloat calculateCellHeight ;
-
- if ([self.delegate respondsToSelector:@selector(tableView:heightForRowAtIndexPath:targetMessage:)]) {
- calculateCellHeight = [self.delegate tableView:tableView heightForRowAtIndexPath:indexPath targetMessage:messageModel];
-
- } else {
- calculateCellHeight = [self calculateCellHeightWithMessage:messageModel atIndexPath:indexPath];
- }
-
- return calculateCellHeight;
- }
- // UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
- return 1;
- }
- //DKPhotoPickerBrowserViewControllerDataSource
- - (NSInteger)numberOfSectionInPhotosInPickerBrowser:(DKPhotoPickerBrowserViewController *)pickerBrowser{
- return self.assets.count;
- }
- //DKPhotoPickerBrowserViewControllerDataSource
- - (NSInteger)photoBrowser:(DKPhotoPickerBrowserViewController *)photoBrowser numberOfItemsInSection:(NSUInteger)section{
- return [self.assets count];
- }
- //DKPhotoPickerBrowserViewControllerDataSource
- - (DKPhotoPickerBrowserPhoto *)photoBrowser:(DKPhotoPickerBrowserViewController *)pickerBrowser photoAtIndexPath:(NSIndexPath *)indexPath{
- id imageObj = [self.assets objectAtIndex:indexPath.item];
- DKPhotoPickerBrowserPhoto *photo = [DKPhotoPickerBrowserPhoto photoAnyImageObjWith:imageObj];
- // 包装下imageObj 成 DKPhotoPickerBrowserPhoto 传给数据源
- LogNewCollectionViewCell *cell = (LogNewCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
- // 缩略图
- photo.thumbImage = cell.imageView.image;
- return photo;
- }
- //DKPhotoPickerBrowserViewControllerDelegate
- - (void)photoBrowser:(DKPhotoPickerBrowserViewController *)photoBrowser removePhotoAtIndexPath:(NSIndexPath *)indexPath{
- if (indexPath.row > [self.assets count]) return;
- [self.assets removeObjectAtIndex:indexPath.row];
- [self.collectionView reloadData];
- }
- //collectionview datasource
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
- CGFloat collectionheight=0;
-
- if (self.assets.count==0) {
- collectionheight=0;
- }else {
-
- collectionheight= [self getPhotoCollectionViewHeightWithPhotos:self.assets];
- }
-
- _collectionView.frame=CGRectMake(10,CGRectGetMaxY(_txtContent.frame)+8, Screen_Width-20, collectionheight);
- _positionImg.frame=CGRectMake(15, CGRectGetMaxY(_collectionView.frame)+15,9,12);
- _lblPosition.frame=CGRectMake(CGRectGetMaxX(_positionImg.frame)+11,CGRectGetMaxY(_collectionView.frame)+10, 350, 20);
- _btnTakePhoto.frame=CGRectMake(15, CGRectGetMaxY(_positionImg.frame)+15,80,20);
- _btnPhoto.frame=CGRectMake((Screen_Width/3)+15, CGRectGetMaxY(_positionImg.frame)+15,80,20);
- _btnPosition.frame=CGRectMake((Screen_Width/3*2)+15, CGRectGetMaxY(_positionImg.frame)+15,80,20);
- _separatorView.frame=CGRectMake(15, CGRectGetMaxY(_btnTakePhoto.frame)+15,Screen_Width-15,1);
- _voiceImg.frame=CGRectMake(17,CGRectGetMaxY(_separatorView.frame)+18, 13, 15);
- _lblVoice.frame=CGRectMake(CGRectGetMaxX(_voiceImg.frame)+13,CGRectGetMaxY(_separatorView.frame)+15,30, 20);
- _btnRecord.frame=CGRectMake(Screen_Width-90, CGRectGetMaxY(_separatorView.frame)+18,100,20);
- _messageTV.frame=CGRectMake(CGRectGetMaxX(_lblVoice.frame)+2, CGRectGetMaxY(_separatorView.frame)+18,140, [self getSoundViewHeight:self.voicePaths]);
- if(self.voicePaths.count>0){
- contentView.frame=CGRectMake(0, 0, Screen_Width,CGRectGetMaxY( _messageTV.frame));
- }
- else{
- contentView.frame=CGRectMake(0, 0, Screen_Width,CGRectGetMaxY(_btnRecord.frame));
- }
-
- scroll.contentSize=CGSizeMake(self.view.frame.size.width, contentView.frame.size.height+110);
-
- return [self.assets count];
- }
- //collectionview datasource
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
-
- LogNewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LogNewCollectionViewCell" forIndexPath:indexPath];
-
- // 判断类型来获取Image
- DKPhotoAssets *asset = self.assets[indexPath.item];
- if ([asset isKindOfClass:[DKPhotoAssets class]]) {
- cell.imageView.image = asset.originImage;
- }else if ([asset isKindOfClass:[NSString class]]){
- [cell.imageView sd_setImageWithURL:[NSURL URLWithString:(NSString *)asset] placeholderImage:[UIImage imageNamed:@"wallpaper_placeholder"]];
- }else if([asset isKindOfClass:[UIImage class]]){
- cell.imageView.image = (UIImage *)asset;
- }else if ([asset isKindOfClass:[DKCamera class]]){
- cell.imageView.image = [(DKCamera*)asset thumbImage];
- }
-
- return cell;
-
- }
- //collectionView Delegate
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
-
- LogNewCollectionViewCell *cell = (LogNewCollectionViewCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
- // 图片游览器
- DKPhotoPickerBrowserViewController *pickerBrowser = [[DKPhotoPickerBrowserViewController alloc] init];
- // 传入点击图片View的话,会有微信朋友圈照片的风格
- pickerBrowser.toView = cell.imageView;
- // 数据源/delegate
- pickerBrowser.delegate = self;
- pickerBrowser.dataSource = self;
- // 是否可以删除照片
- pickerBrowser.editing = YES;
- // 当前选中的值
- pickerBrowser.currentIndexPath = [NSIndexPath indexPathForItem:indexPath.row inSection:0];
- // 展示控制器
- [pickerBrowser show];
- }
- //分享事件回调函数
- - (void)reShareData:(NSArray *)sarray
- {
- if(self.shareArr==nil){
- self.shareArr=[NSMutableArray new];
- }
- [self.shareArr removeAllObjects];
- [self.shareArr addObjectsFromArray:sarray];
- NSMutableArray* ids=[NSMutableArray new];
- NSMutableArray* names=[NSMutableArray new];
-
-
- for (int i=0; i<self.shareArr.count; i++) {
- LogShareAndCommentInfoModel* model=self.shareArr[i];
- [names addObject:model.userName];
- [ids addObject:model.userId];
- }
- if(self.shareArr!=nil && self.shareArr.count>0){
- self.sShareId=[ ids componentsJoinedByString:@","];
- self.sShareUserName=[names componentsJoinedByString:@","];
-
- [_btnShare setTitle:self.sShareUserName forState:UIControlStateNormal];
- [_btnComment setTitle:@"请选择点评人" forState:UIControlStateNormal];
- self.sCommentId = @"";
- self.sComment = @"";
- }
-
-
- }
- // 评论事件回调函数
- - (void)reCommentData:(LogShareAndCommentInfoModel*)model
- {
- if(self.commentArr==nil){
- self.commentArr=[NSMutableArray new];
- }
- [self.commentArr removeAllObjects];
- [self.commentArr addObject:model ];
-
- NSMutableArray* ids=[NSMutableArray new];
- NSMutableArray* names=[NSMutableArray new];
-
- for (int i=0; i<self.commentArr.count; i++) {
- LogShareAndCommentInfoModel* model=self.commentArr[i];
- [names addObject:model.userName];
- [ids addObject:model.userId];
- }
- if(self.commentArr!=nil && self.commentArr.count>0){
- self.sCommentId=[ ids componentsJoinedByString:@","];
- self.sComment=[names componentsJoinedByString:@","];
-
- [_btnComment setTitle:self.sComment forState:UIControlStateNormal];
- }
-
-
- }
- //照片选择完回调方法
- - (void)pickerViewControllerDoneAsstes:(NSArray *)assets{
- for (int i=(int)self.assets.count-1;i>=0;i-- ) {
- if ([self.assets[i] isKindOfClass:[DKPhotoAssets class]]) {
- [self.assets removeObject:self.assets[i]];
- }
- }
- for (DKPhotoAssets* asset in assets ) {
- if ([asset isKindOfClass:[DKPhotoAssets class]]) {
- [self.assets addObject:asset];
- }
- }
-
- [self.collectionView reloadData];
- }
- #pragma mark - 私有方法
- //获得录音路径
- - (NSString *)getRecorderPath {
- NSString *recorderPath = nil;
- recorderPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex: 0];
- NSDate *now = [NSDate date];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyyMMddHHmmssSSS"];
- recorderPath = [recorderPath stringByAppendingFormat:@"%@-MySound.aac", [dateFormatter stringFromDate:now]];
- return recorderPath;
- }
- //tableview底部间距
- - (UIEdgeInsets)tableViewInsetsWithBottomValue:(CGFloat)bottom {
- UIEdgeInsets insets = UIEdgeInsetsZero;
-
- if ([self respondsToSelector:@selector(topLayoutGuide)]) {
- insets.top = 2;//self.topLayoutGuide.length;
- }
-
- insets.bottom = bottom;
-
- return insets;
- }
- // 计算消息的高度
- - (CGFloat)calculateCellHeightWithMessage:(id <DKMessageModel>)message atIndexPath:(NSIndexPath *)indexPath {
- CGFloat cellHeight = 0;
-
-
- cellHeight = [DKUITableViewCell calculateCellHeightWithMessage:message displaysTimestamp:NO];
-
- return cellHeight;
- }
- //发送语音方法
- - (void)didSendMessageWithVoice:(NSString *)voicePath voiceDuration:(NSString*)voiceDuration {
- if ([self.delegate respondsToSelector:@selector(didSendVoice:voiceDuration:fromSender:onDate:)]) {
- [self.delegate didSendVoice:voicePath voiceDuration:voiceDuration fromSender:self.messageSender onDate:[NSDate date]];
- }
- }
- // Other Menu View Frame Helper Mehtod
- - (void)layoutOtherMenuViewHiden:(BOOL)hide {
- [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
- __block CGRect inputViewFrame = _inputView.frame;
- __block CGRect otherMenuViewFrame;
-
- void (^InputViewAnimation)(BOOL hide) = ^(BOOL hide) {
- inputViewFrame.origin.y = (hide ? (CGRectGetHeight(self.view.bounds) - CGRectGetHeight(inputViewFrame)) : (CGRectGetMinY(otherMenuViewFrame) - CGRectGetHeight(inputViewFrame)));
- _inputView.frame = inputViewFrame;
- };
-
-
-
- InputViewAnimation(hide);
- } completion:^(BOOL finished) {
-
- }];
- }
- //录音完成方法
- - (void)prepareRecordWithCompletion:(DKPrepareRecorderCompletion)completion {
- [self.voiceRecordHelper prepareRecordingWithPath:[self getRecorderPath] prepareRecorderCompletion:completion];
- }
- //开始录音方法
- - (void)startRecord {
- [self.voiceRecordHUD startRecordingHUDAtView:self.view];
- [self.voiceRecordHelper startRecordingWithStartRecorderCompletion:^{
- }];
- }
- //完成录音方法
- - (void)finishRecorded {
- WEAKSELF
- [self.voiceRecordHUD stopRecordCompled:^(BOOL fnished) {
- weakSelf.voiceRecordHUD = nil;
- }];
- [self.voiceRecordHelper stopRecordingWithStopRecorderCompletion:^{
- [weakSelf didSendMessageWithVoice:weakSelf.voiceRecordHelper.recordPath voiceDuration:weakSelf.voiceRecordHelper.recordDuration];
- }];
- }
- /**
- * 改变数据源需要的子线程
- *
- * @param queue 子线程执行完成的回调block
- */
- - (void)exChangeMessageDataSourceQueue:(void (^)())queue {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), queue);
- }
- /**
- * 执行块代码在主线程
- *
- * @param queue 主线程执行完成回调block
- */
- - (void)exMainQueue:(void (^)())queue {
- dispatch_async(dispatch_get_main_queue(), queue);
- }
- //停止录音方法
- - (void)pauseRecord {
- [self.voiceRecordHUD pauseRecord];
- }
- //恢复录音方法
- - (void)resumeRecord {
- [self.voiceRecordHUD resaueRecord];
- }
- //取消录音方法
- - (void)cancelRecord {
- WEAKSELF
- [self.voiceRecordHUD cancelRecordCompled:^(BOOL fnished) {
- weakSelf.voiceRecordHUD = nil;
- }];
- [self.voiceRecordHelper cancelledDeleteWithCompletion:^{
-
- }];
- }
- //准备录音完成方法
- - (void)prepareRecordingVoiceActionWithCompletion:(BOOL (^)(void))completion {
- [self prepareRecordWithCompletion:completion];
- }
- //开始录音事件方法
- - (void)didStartRecordingVoiceAction {
- [self startRecord];
- }
- //取消录音事件方法
- - (void)didCancelRecordingVoiceAction {
- [self cancelRecord];
- }
- //完成录音事件方法
- - (void)didFinishRecordingVoiceAction {
- if (self.isMaxTimeStop == NO) {
- [self finishRecorded];
- } else {
- self.isMaxTimeStop = NO;
- }
- }
- //手指移出事件
- - (void)didDragOutsideAction {
- [self resumeRecord];
- }
- //手指移入事件
- - (void)didDragInsideAction {
- [self pauseRecord];
- }
- //获得声音 tableviewcell高度
- - (CGFloat)getSoundViewHeight:(NSMutableArray *)soundArray {
- // 上下间隔已经在frame上做了
- NSInteger row = soundArray.count;
- return row*50;
- }
- //添加消息
- - (void)addMessage:(DKMessage *)addedMessage {
- WEAKSELF
- [self exChangeMessageDataSourceQueue:^{
- NSMutableArray *messages = [NSMutableArray arrayWithArray:weakSelf.messages];
- [messages addObject:addedMessage];
-
- NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:1];
- [indexPaths addObject:[NSIndexPath indexPathForRow:messages.count - 1 inSection:0]];
-
- [weakSelf exMainQueue:^{
- weakSelf.messages = messages;
- [_messageTV insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
- [weakSelf scrollToBottomAnimated:YES];
- }];
- }];
- }
- //滚动到底部动画
- - (void)scrollToBottomAnimated:(BOOL)animated {
- NSInteger rows = [_messageTV numberOfRowsInSection:0];
-
- if (rows > 0) {
- [_messageTV scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:rows - 1 inSection:0]
- atScrollPosition:UITableViewScrollPositionBottom
- animated:animated];
- }
- }
- //滚动到指定行
- - (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath
- atScrollPosition:(UITableViewScrollPosition)position
- animated:(BOOL)animated {
-
- [_messageTV scrollToRowAtIndexPath:indexPath
- atScrollPosition:position
- animated:animated];
- }
- //初始化布局
- -(void)initUI{
- scroll=[UIScrollView new];
- scroll.tag=1001;
- scroll.delegate=self;
- [self.view addSubview:scroll];
- scroll.frame=self.view.bounds;
- contentView=[[UIView alloc]init];
- contentView.frame=CGRectZero;
- self.view.backgroundColor=[UIColor whiteColor];
- [scroll addSubview:contentView];
- UITapGestureRecognizer* gesture=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKey)];
- gesture.cancelsTouchesInView=NO;
- [contentView addGestureRecognizer:gesture];
-
- UILabel* lblUserName=[[UILabel alloc] init];
- lblUserName.frame=CGRectMake(15, 15, 100, 25);
- lblUserName.text=@"姓 名";
- lblUserName.font=logTextFont;
- [contentView addSubview:lblUserName];
-
- UITextField* textUserName=[[UITextField alloc] init];
- textUserName.frame=CGRectMake(130, 15, 150, 25);
- textUserName.textColor=ButtonTitleColor;
- textUserName.text=kkUserName;
- textUserName.font=logTextFont;
- textUserName.enabled=NO;
- [contentView addSubview:textUserName];
- UIView *userNameSeparator=[[UIView alloc]init];
- userNameSeparator.frame=CGRectMake(130,CGRectGetMaxY(textUserName.frame)+14,Screen_Width-145,1);
- userNameSeparator.backgroundColor=LineBackgroundColor;
- [contentView addSubview: userNameSeparator];
-
- UILabel* lblDate=[[UILabel alloc] init];
- lblDate.frame=CGRectMake(15,CGRectGetMaxY(userNameSeparator.frame)+15, 100, 25);
- lblDate.text=@"日 期";
- lblDate.font=logTextFont;
- [contentView addSubview:lblDate];
- _btnDate=[UIButton buttonWithType:UIButtonTypeCustom];
- _btnDate.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- _btnDate.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
- _btnDate.frame=CGRectMake(130,CGRectGetMaxY(userNameSeparator.frame)+15, 150, 25);
- [_btnDate setTitle:@"请选择日志日期" forState:UIControlStateNormal];
- [_btnDate setTitleColor:ButtonTitleColor forState:UIControlStateNormal];
- _btnDate.titleLabel.font=logTextFont;
- [_btnDate addTarget:self action:@selector(showStartSelect) forControlEvents:UIControlEventTouchUpInside];
- [contentView addSubview:_btnDate];
- UIView *dateSeparator=[[UIView alloc]init];
- dateSeparator.frame=CGRectMake(130,CGRectGetMaxY(_btnDate.frame)+14,Screen_Width-145,1);
- dateSeparator.backgroundColor=LineBackgroundColor;
- [contentView addSubview: dateSeparator];
- UILabel* lblScope=[[UILabel alloc] init];
- lblScope.frame=CGRectMake(15,CGRectGetMaxY(dateSeparator.frame)+15, 100, 25);
- lblScope.text=@"范围权限";
- lblScope.font=logTextFont;
- [contentView addSubview:lblScope];
-
- _btnShare=[UIButton buttonWithType:UIButtonTypeCustom];
- _btnShare.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- _btnShare.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
- _btnShare.frame=CGRectMake(130,CGRectGetMaxY(dateSeparator.frame)+15, 300, 25);
- [_btnShare setTitle:@"请选择范围权限" forState:UIControlStateNormal];
- [_btnShare setTitleColor:ButtonTitleColor forState:UIControlStateNormal];
- _btnShare.titleLabel.font=logTextFont;
- [_btnShare addTarget:self action:@selector(showScope) forControlEvents:UIControlEventTouchUpInside];
- [contentView addSubview:_btnShare];
- UIView *scopeSeparator=[[UIView alloc]init];
- scopeSeparator.frame=CGRectMake(130,CGRectGetMaxY(_btnShare.frame)+14,Screen_Width-145, 1);
- scopeSeparator.backgroundColor=LineBackgroundColor;
- [contentView addSubview: scopeSeparator];
-
- UILabel* lblChecker=[[UILabel alloc] init];
- lblChecker.frame=CGRectMake(15,CGRectGetMaxY(scopeSeparator.frame)+15, 100, 25);
- lblChecker.text=@"点 评 人";
- lblChecker.font=logTextFont;
- [contentView addSubview:lblChecker];
- _btnComment=[UIButton buttonWithType:UIButtonTypeCustom];
- _btnComment.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- _btnComment.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
- _btnComment.frame=CGRectMake(130,CGRectGetMaxY(scopeSeparator.frame)+15, 150, 25);
- [_btnComment setTitle:@"请选择点评人" forState:UIControlStateNormal];
- [_btnComment setTitleColor:ButtonTitleColor forState:UIControlStateNormal];
- _btnComment.titleLabel.font=logTextFont;
- [_btnComment addTarget:self action:@selector(showComment) forControlEvents:UIControlEventTouchUpInside];
- [contentView addSubview:_btnComment];
- UIView *selectView=[[UIView alloc]init];
- selectView.frame=CGRectMake(0, CGRectGetMaxY(lblChecker.frame)+15, Screen_Width,40);
- selectView.backgroundColor=LineBackgroundColor;
- UILabel *selectBackgroundView=[[UILabel alloc]init];
- selectBackgroundView.frame=CGRectMake(14,13,100,25);
- UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"selectBackground"]];
- [selectBackgroundView setBackgroundColor:color];
- selectBackgroundView.text=@" 以下均为选填";
- selectBackgroundView.font=logTextFont;
- [selectView addSubview:selectBackgroundView];
- [contentView addSubview:selectView];
-
- _txtContent=[[UITextView alloc] init];
- _txtContent.frame=CGRectMake(15,CGRectGetMaxY(selectView.frame)+15,Screen_Width-30,100);
- _txtContent.textColor=[UIColor blackColor];
- _txtContent.font=logTextFont;
- _txtContent.delegate=self;
- _txtContent.tag=101;
- [contentView addSubview:_txtContent];
- UILabel *placeHolderLabel = [[UILabel alloc] init];
- placeHolderLabel.text = @"请填写日志内容";
- placeHolderLabel.numberOfLines = 0;
- placeHolderLabel.textColor = ButtonTitleColor;
- placeHolderLabel.font=logTextFont;
- [placeHolderLabel sizeToFit];
- [_txtContent addSubview: placeHolderLabel];
- [_txtContent setValue:placeHolderLabel forKey:@"_placeholderLabel"];
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
- flowLayout.itemSize = CGSizeMake(80,80);
- flowLayout.minimumInteritemSpacing = 5;
- flowLayout.minimumLineSpacing = 10;
-
- flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
- _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(_txtContent.frame)+8, Screen_Width-20, 1) collectionViewLayout:flowLayout];
- _collectionView.backgroundColor = [UIColor clearColor];
- _collectionView.dataSource = self;
- _collectionView.delegate = self;
-
- [_collectionView registerNib:[UINib nibWithNibName:@"LogNewCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"LogNewCollectionViewCell"];
- [contentView addSubview:_collectionView];
- _positionImg=[[UIImageView alloc]init];
- _positionImg.frame=CGRectMake(15, CGRectGetMaxY(_collectionView.frame),9,12);
- [_positionImg setImage:[UIImage imageNamed:@"log_position"]];
- [contentView addSubview:_positionImg];
- _lblPosition=[[UILabel alloc]init];
- _lblPosition.frame=CGRectMake(CGRectGetMaxX(_positionImg.frame)+11,CGRectGetMaxY(_collectionView.frame)+10, 350, 20);
- _lblPosition.font=logTextFont;
- [contentView addSubview:_lblPosition];
- _btnTakePhoto=[UIButton buttonWithType:UIButtonTypeCustom];
- _btnTakePhoto.frame=CGRectMake(15, CGRectGetMaxY(_positionImg.frame)+15,80,20);
- [contentView addSubview:_btnTakePhoto];
- UIImageView *takephotoImg=[[UIImageView alloc]init];
- takephotoImg.frame=CGRectMake(0,3, 18, 15);
- [takephotoImg setImage:[UIImage imageNamed:@"icon_takephoto"]];
- takephotoImg.userInteractionEnabled=NO;
- [_btnTakePhoto addSubview:takephotoImg];
- UILabel *lblTakePhoto=[[UILabel alloc]init];
- lblTakePhoto.text=@"照相";
- lblTakePhoto.font=logTextFont;
- lblTakePhoto.frame=CGRectMake(CGRectGetMaxX(takephotoImg.frame)+11,0,50, 20);
- [_btnTakePhoto addSubview:lblTakePhoto];
- [_btnTakePhoto addTarget:self action:@selector(selectCamera) forControlEvents:UIControlEventTouchUpInside];
- _btnPhoto=[UIButton buttonWithType:UIButtonTypeCustom];
- _btnPhoto.frame=CGRectMake((Screen_Width/3)+15, CGRectGetMaxY(_positionImg.frame)+15,80,20);
- [contentView addSubview:_btnPhoto];
- UIImageView *photoImg=[[UIImageView alloc]init];
- photoImg.userInteractionEnabled=NO;
- photoImg.frame=CGRectMake(0,3, 18, 15);
- [photoImg setImage:[UIImage imageNamed:@"icon_photo"]];
- [_btnPhoto addSubview:photoImg];
- UILabel *lblPhoto=[[UILabel alloc]init];
- lblPhoto.text=@"相册";
- lblPhoto.font=logTextFont;
- lblPhoto.frame=CGRectMake(CGRectGetMaxX(photoImg.frame)+11,0,50, 20);
- [_btnPhoto addSubview:lblPhoto];
- [_btnPhoto addTarget:self action:@selector(selectPhotos) forControlEvents:UIControlEventTouchUpInside];
-
- _btnPosition=[UIButton buttonWithType:UIButtonTypeCustom];
- _btnPosition.frame=CGRectMake((Screen_Width/3*2)+15, CGRectGetMaxY(_positionImg.frame)+15,80,20);
- [contentView addSubview:_btnPosition];
- [_btnPosition addTarget:self action:@selector(selectPosition) forControlEvents:UIControlEventTouchUpInside];
- UIImageView *mapPositionImg=[[UIImageView alloc]init];
- mapPositionImg.userInteractionEnabled=NO;
- mapPositionImg.frame=CGRectMake(0,3, 13, 15);
- [ mapPositionImg setImage:[UIImage imageNamed:@"icon_position"]];
- [_btnPosition addSubview: mapPositionImg];
- UILabel *lblPosition=[[UILabel alloc]init];
- lblPosition.text=@"所在位置";
- lblPosition.font=logTextFont;
- lblPosition.frame=CGRectMake(CGRectGetMaxX(mapPositionImg.frame)+11,0,80, 20);
- [_btnPosition addSubview:lblPosition];
- _separatorView=[[UIView alloc]init];
- _separatorView.frame=CGRectMake(15, CGRectGetMaxY(_btnTakePhoto.frame)+15,Screen_Width-15, 1);
- _separatorView.backgroundColor=LineBackgroundColor;
- [contentView addSubview:_separatorView];
- _voiceImg=[[UIImageView alloc]init];
- _voiceImg.frame=CGRectMake(17,CGRectGetMaxY(_separatorView.frame)+18, 13, 15);
- [_voiceImg setImage:[UIImage imageNamed:@"icon_voice"]];
- [contentView addSubview:_voiceImg];
- _lblVoice=[[UILabel alloc]init];
- _lblVoice.text=@"语音";
- _lblVoice.font=logTextFont;
- _lblVoice.frame=CGRectMake(CGRectGetMaxX(_voiceImg.frame)+13,CGRectGetMaxY(_separatorView.frame)+15,30, 20);
- [contentView addSubview:_lblVoice];
- _messageTV = [[DKMessageTableView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_lblVoice.frame)+2, CGRectGetMaxY(_separatorView.frame)+18,190, 1) style:UITableViewStylePlain];
- _messageTV.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- _messageTV.dataSource = self;
- _messageTV.delegate = self;
- _messageTV.separatorStyle = UITableViewCellSeparatorStyleNone;
- [contentView addSubview:_messageTV];
- _btnRecord=[UIButton buttonWithType:UIButtonTypeCustom];
- _btnRecord.frame=CGRectMake(Screen_Width-90, CGRectGetMaxY(_separatorView.frame)+18,100,20);
- [contentView addSubview:_btnRecord];
- UIImageView *recordImg=[[UIImageView alloc]init];
- recordImg.frame=CGRectMake(0,3, 14, 15);
- recordImg.userInteractionEnabled=NO;
- [recordImg setImage:[UIImage imageNamed:@"longpressed"]];
- [_btnRecord addSubview:recordImg];
- [_btnRecord addTarget:self action:@selector(switchKeyboard) forControlEvents:UIControlEventTouchUpInside];
- UILabel *lblRecord=[[UILabel alloc]init];
- lblRecord.text=@"长按录音";
- lblRecord.textColor=LabelGrayTextColor;
- lblRecord.font=logTextFont;
- lblRecord.frame=CGRectMake(CGRectGetMaxX(recordImg.frame)+3,0,80, 20);
- [_btnRecord addSubview:lblRecord];
- contentView.frame=CGRectMake(0, 0, Screen_Width,CGRectGetMaxY(_btnRecord.frame));
- // 输入工具条的frame
- CGRect inputFrame = CGRectMake(0.0f,
- self.view.frame.size.height - 45.0,
- self.view.frame.size.width,
- 45.0);
-
- // 初始化输入工具条
- _inputView = [[DKMessageInputView alloc] initWithFrame:inputFrame];
- _inputView.allowsSendVoice = self.allowsSendVoice;
- _inputView.delegate = self;
- [self.view addSubview:_inputView];
- [self.view bringSubviewToFront:_inputView];
-
-
- }
- // 保存前的校验
- -(BOOL)check
- {
- if(_sDate ==nil || [NSString stringWithFormat:@"%@",_sDate ].length==0)
- {
- [self showAlertViewText:@"请选择日志日期"];
- return NO;
- }
- if(_txtContent.text ==nil || [NSString stringWithFormat:@"%@",_txtContent.text ].length==0)
- {
- [self showAlertViewText:@"请输入日志内容"];
- return NO;
- }
- if(_sShareId ==nil ||[NSString stringWithFormat:@"%@",_sShareId ].length==0)
- {
- [self showAlertViewText:@"请选择分享范围"];
- return NO;
- }
- if(_sCommentId ==nil || [NSString stringWithFormat:@"%@",_sCommentId ].length==0)
- {
- [self showAlertViewText:@"请选择点评人"];
- return NO;
- }
-
-
- return YES;
- }
- // 上传图片和语音
- -(BOOL)saveImageAndVioceManager{
- _mDownManager = [[ASIDownManager alloc] init];
- _mDownManager.delegate = self;
- //////////////上传语音
- NSString *urlStr = ServerURL;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"SaveSound" forKey:@"Action"];
-
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
-
- [self.voiceUploadPaths removeAllObjects];
- for (int i=0; i<self.voicePaths.count; i++) {
- NSString* retValue= [_mDownManager syncPostHttpRequestUrl:urlStr dic:dict path:self.voicePaths[i] filename:nil fileType: @"audio/x-flac"];
- // NSString* retValue= [_mDownManager SyncPostHttpRequest:urlStr :dict :self.voicePaths[i] :nil :@"audio/x-flac"];
- if (retValue==nil || retValue.length==0){
- [self cancel];
- [self showAlertViewText:@"上传语音失败"];
- self.navigationItem.rightBarButtonItem.enabled=YES;
- return NO;
- }
- NSDictionary *dicRetValue = [retValue JSONValue];
- if (dicRetValue && [dicRetValue isKindOfClass:[NSDictionary class]]) {
- int iStatus = [[dicRetValue objectForKey:@"Status"] intValue];
- //NSString *message=[dicRetValue objectForKey:@"Message"];
- if (iStatus == 0) {
- NSString * voicePath=[dicRetValue objectForKey:@"Result"];
- [self.voiceUploadPaths addObject:voicePath];
-
- }
- }
-
- }
-
- [self.imageLocalPaths removeAllObjects];
- [self.imagePaths removeAllObjects];
- _mDownManager = [[ASIDownManager alloc] init];
- _mDownManager.delegate = self;
- dict = [NSMutableDictionary dictionary];
- [dict setObject:@"SaveImg" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
-
-
- for (int i=0; i<self.assets.count; i++) {
- DKPhotoAssets *asset = self.assets[i];
- DKCamera * c;
- if ([asset isKindOfClass:[DKPhotoAssets class]]) {
- c=[self saveImage:asset.originImage withName:nil];
-
- }else if ([asset isKindOfClass:[NSString class]]){
-
- }else if([asset isKindOfClass:[UIImage class]]){
-
- }else if ([asset isKindOfClass:[DKCamera class]]){
- c=(DKCamera *)asset;
- }
- [self.imageLocalPaths addObject:c.imagePath];
- NSString* retValue= [_mDownManager syncPostHttpRequestUrl:urlStr dic:dict path:c.imagePath filename:nil fileType:@"image/jpeg"];
- //NSString* retValue= [_mDownManager SyncPostHttpRequest:urlStr :dict :c.imagePath :nil:@"image/jpeg"];
- if (retValue==nil || retValue.length==0){
- //[self Cancel];
- [self showAlertViewText:@"上传图片失败"];
- return NO;
- }
- NSDictionary *dicRetValue = [retValue JSONValue];
- if (dicRetValue && [dicRetValue isKindOfClass:[NSDictionary class]]) {
- int iStatus = [[dicRetValue objectForKey:@"Status"] intValue];
- //NSString *message=[dicRetValue objectForKey:@"Message"];
- if (iStatus == 0) {
- NSString * imgPath=[dicRetValue objectForKey:@"Result"];
- [self.imagePaths addObject:imgPath];
-
- }
- }
-
- }
-
- return YES;
- }
- //画面清空
- -(void)clearSenderData{
- _txtContent.text=@"";
- _sShareUserName=@"";
- _sShareId=@"";
- _sComment=@"";
- _sCommentId=@"";
- [_btnShare setTitle:@"请选择分享范围" forState:UIControlStateNormal];
- [_btnComment setTitle:@"请选择点评人" forState:UIControlStateNormal];
- self.lblPosition.text=@"";
- vPositionView.hidden=YES;
- UIDatePicker * picker=[[UIDatePicker alloc] init];
- NSDate *select = [picker date];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- _sDate = [dateFormatter stringFromDate:select];
-
- NSString *date= [DateFormat dateFormatSplit:_sDate];
- [_btnDate setTitle:date forState:UIControlStateNormal];
- NSFileManager * fileManager = [[NSFileManager alloc]init];
- for (NSString* imgPath in self.imageLocalPaths ) {
- [fileManager removeItemAtPath:imgPath error:nil];
- }
- for (NSString* voicePath in self.voiceUploadPaths) {
- [fileManager removeItemAtPath:voicePath error:nil];
- }
-
- [self.imageLocalPaths removeAllObjects];
- [self.voiceUploadPaths removeAllObjects];
- [self.voiceUploadTimes removeAllObjects];
- [self.voicePaths removeAllObjects];
- [self.assets removeAllObjects];
- [self.collectionView reloadData];
- [self.messages removeAllObjects];
- [_messageTV reloadData];
- }
- //取消进度条加载
- - (void)cancel {
- [self stopLoading];
- }
- //保存日志
- -(void)saveLog{
- if([self check]==NO){
- return ;
- }
- self.navigationItem.rightBarButtonItem.enabled=NO;
-
- [self startLoading];
- // jiangyh add 2017-07-14 add
- // 先保存图片 ,后保存数据
- [self startLoading];
- dispatch_async(dispatch_get_global_queue(0,0), ^{
- if ([self saveImageAndVioceManager]) {
- [self saveDataManager];
- }
- });
- // if ([self saveImageAndVioceManager]) {
- // [self saveDataManager];
- // }
- // jiangyh add 2017-07-14 end
-
- }
- //保存数据
- -(void)saveDataManager{
- _mDownManager = [[ASIDownManager alloc] init];
- _mDownManager.delegate = self;
- _mDownManager.OnImageDown = @selector(onLoadFinish:);
- _mDownManager.OnImageFail = @selector(onLoadFail:);
-
- NSString *urlStr = ServerURL;
- NSMutableDictionary *dict = [NSMutableDictionary dictionary];
- [dict setObject:@"SaveDailyRecordManager" forKey:@"Action"];
- [dict setObject:[NSString stringWithFormat:@"%@",kkAccountCode]forKey:@"AccountCode"];
- [dict setObject:kkUserCode forKey:@"UserCode"];
- [dict setObject:kkUserPwd forKey:@"UserPassword"];
- [dict setObject:kkSessionKey forKey:@"SessionKey"];
- [dict setObject:@"0" forKey:@"RecordStatus"];
- [dict setObject:self.txtContent.text forKey:@"RecordContent"];
- [dict setObject:@"1" forKey:@"RecordSource"];
- [dict setObject:self.sDate forKey:@"CreateTime"];
- [dict setObject:self.sShareId forKey:@"PreviewUserIDs"];
- [dict setObject:self.sCommentId forKey:@"CommentUserID"];
- if(self.sLocation!=nil && self.sLocation.length>0){
- [dict setObject:self.sLocation forKey:@"RecordLocation"];
- }
-
- /////////图片上传返回的地址
- if (self.imagePaths && self.imagePaths.count>0) {
- [dict setObject:[self.imagePaths componentsJoinedByString:@"," ] forKey:@"ImagePath"];
- }
-
- if (self.voiceUploadPaths && self.voiceUploadPaths.count>0) {
- [dict setObject:[self.voiceUploadPaths componentsJoinedByString:@"," ] forKey:@"SoundPath"];
- }
- if (self.voiceUploadTimes && self.voiceUploadTimes.count>0) {
- [dict setObject:[self.voiceUploadTimes componentsJoinedByString:@"," ] forKey:@"SoundTime"];
- }
-
- [_mDownManager postHttpRequest:urlStr dic:dict path:nil fileName:nil];
- }
- //切换底部布局
- -(void)switchKeyboard{
- if(_inputView!=nil){
- if(_inputView.saveButton.hidden==YES){
- _inputView.saveButton.hidden=NO;
- _inputView.switchButton.hidden=YES;
- _inputView.voiceButton.hidden=YES;
- }
- else{
- _inputView.saveButton.hidden=YES;
- _inputView.switchButton.hidden=NO;
- _inputView.voiceButton.hidden=NO;
- }
- }
- }
- //保存图片至沙盒
- - (DKCamera *) saveImage:(UIImage *)currentImage withName:(NSString *)imageName
- {
- if (!currentImage) {
- return nil;
- }
-
- NSDateFormatter *formater = [[NSDateFormatter alloc] init];
- formater.dateFormat = @"yyyyMMddHHmmss";
- NSString *currentTimeStr = [[formater stringFromDate:[NSDate date]] stringByAppendingFormat:@"_%d_.jpg" ,arc4random_uniform(10000)];
-
- NSData *imageData= [LeslieAsyncImageDownloader resetSizeOfImageData:currentImage maxSize:500];
- // 获取沙盒目录
- NSString *fullPath ;
- if([imageName isEqualToString:@""] || imageName==nil){
- fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:currentTimeStr];
- }
- else{
- fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
- }
-
- // 将图片写入文件
- [imageData writeToFile:fullPath atomically:NO];
-
- UIImage *savedImage = [[UIImage alloc] initWithContentsOfFile:fullPath];
-
- //NSData *data = UIImageJPEGRepresentation(savedImage, 0.3);
- DKCamera *camera = [[DKCamera alloc] init];
- camera.imagePath = fullPath;
- camera.thumbImage =savedImage;// [UIImage imageWithData:data];
- return camera;
- }
- //选择地图方法
- -(void)selectPosition{
- MapViewController *mc=[MapViewController new];
- mc.pDelegate=self;
- [self.navigationController pushViewController:mc animated:YES];
- }
- //相机拍照方法
- -(void)selectCamera{
- DKCameraViewController *cameraVc = [[DKCameraViewController alloc] init];
- __weak typeof(self) weakSelf = self;
- // 多选相册+相机多拍 回调
- [cameraVc startCameraOrPhotoFileWithViewController:self complate:^(NSArray *object) {
- // 选择完照片、拍照完回调
- [object enumerateObjectsUsingBlock:^(id asset, NSUInteger idx, BOOL *stop) {
- if(weakSelf.assets.count<9){
- if ([asset isKindOfClass:[DKCamera class]]) {
- [weakSelf.assets addObject:asset];
- }else{
- [weakSelf.assets addObject:asset];
- }
- }else{
- [self showAlertViewText:@"最多只能选择9张图片"];
- }
-
-
- }];
- [weakSelf.collectionView reloadData];
- }];
- self.cameraVc = cameraVc;
-
- }
- #pragma mark - select Photo Library
- -(NSInteger)cameraCount{
- NSInteger count=0;
- for (int i=0; i<self.assets.count; i++) {
- id asset=self.assets[i];
- if ([asset isKindOfClass:[DKCamera class]]) {
- count++;
- }
- }
- return count;
- }
- //选择相册方法
- - (void)selectPhotos {
- // 创建控制器
- DKPhotoPickerViewController *pickerVc = [[DKPhotoPickerViewController alloc] init];
- // 默认显示相册里面的内容SavePhotos
- pickerVc.status = PickerViewShowStatusCameraRoll;
- pickerVc.selectPickers = self.assets;
- // 最多能选9张图片
- pickerVc.minCount = 9;
- pickerVc.cameraCount=[self cameraCount];
- pickerVc.delegate = self;
- [pickerVc show];
- }
- // 获得相册collectionview的高度
- - (CGFloat)getPhotoCollectionViewHeightWithPhotos:(NSMutableArray *)photos {
- // 上下间隔已经在frame上做了
- NSInteger row = (photos.count / 3 + (photos.count % 3 ? 1 : 0));
- return (row *80 + (row *10));
- }
- //显示评论对话框
- -(void)showComment{
- if(_sShareId==nil || _sShareId.length==0){
- [super showAlertViewText:@"请选择分享范围"];
- return;
- }
- [self.view endEditing:YES];
- self.hidesBottomBarWhenPushed=YES;
-
- LogCommentVC *tc=[[LogCommentVC alloc] init];
- tc.commentDelegate=self;
- [tc.filterArr addObjectsFromArray: self.shareArr];
- [self.navigationController pushViewController:tc animated:YES];
- }
- //显示分享范围对话框
- -(void)showScope
- {
- [self.view endEditing:YES];
- self.hidesBottomBarWhenPushed=YES;
- LogShareVC *tc=[LogShareVC new];
- tc.shareDelegate=self;
- tc.tag=@"logAdd";
- [self.navigationController pushViewController:tc animated:YES];
-
-
- }
- //显示开始日期控件
- -(void)showStartSelect
- {
- __weak typeof(self) weakself=self;
-
- _brdatePicker = [BRDatePickerView PickerAlertWithTitle:@""];
- [_brdatePicker configureSelectionBlock:^(NSString *date){
- _displayDate=date;
- } andCompletionBlock:^(void){
- UIDatePicker * picker=[[UIDatePicker alloc] init];
- NSDate *select = [picker date];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"HH:mm:ss"];
- NSString *time = [dateFormatter stringFromDate:select];
- _sDate = [NSString stringWithFormat: @"%@ %@",_displayDate,time];
- [weakself.btnDate setTitle:_displayDate forState:UIControlStateNormal];
- } andCancelBlock:^(void){
-
- _displayDate=weakself.btnDate.titleLabel.text;
- UIDatePicker * picker=[[UIDatePicker alloc] init];
- NSDate *select = [picker date];
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"HH:mm:ss"];
- NSString *time = [dateFormatter stringFromDate:select];
- _sDate = [NSString stringWithFormat: @"%@ %@",_displayDate,time];
-
- }];
- [_brdatePicker show];
-
- }
- //隐藏键盘方法
- -(void)hideKey
- {
- [self.view endEditing:YES];
- }
- /**
- * 返回函数
- */
- -(void)goBack
- {
- [self.navigationController popViewControllerAnimated:YES];
- if([self.refreshDelegate respondsToSelector:@selector(refreshData)]){
- [self.refreshDelegate refreshData];
- }
-
- }
- @end
|