// // PublishViewController.m // model // // Created by liufei on 2018/7/25. // Copyright © 2018年 Mine. All rights reserved. // #import "PublishViewController.h" #import "UITextView+WZB.h" #import "PhotoCollectionViewCell.h" @interface PublishViewController () { UIImagePickerController *pickerVc; } @property (nonatomic, strong) UITextView *pubTextView; @property (nonatomic, strong) NSMutableArray *dataSource; @property (nonatomic, strong) UICollectionView *photoListView; @property (nonatomic, strong) NSMutableArray *imageSource; @end @implementation PublishViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // [self.navigationController.navigationBar setShadowImage:[UIImage new]]; self.navigationController.navigationBar.translucent = NO; } - (void)viewDidLoad { [super viewDidLoad]; self.imageSource = [NSMutableArray new]; self.dataSource = [NSMutableArray new]; [self configUI]; // Do any additional setup after loading the view. } - (void)configUI { self.view.backgroundColor = [UIColor whiteColor]; self.navigationController.navigationBar.barTintColor = [UIColor whiteColor]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(handleCancel)]; [self.navigationItem.leftBarButtonItem setTintColor:[UIColor blackColor]]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"发表" style:UIBarButtonItemStylePlain target:self action:@selector(handlePublish)]; [self.navigationItem.rightBarButtonItem setTintColor:[UIColor colorWithHexString:@"#fe4086"]]; self.pubTextView = [[UITextView alloc] initWithFrame:CGRectMake(40, 40, ScreenWidth - 80, 76)]; self.pubTextView.wzb_placeholder = @"这一刻的想法..."; self.pubTextView.font = [UIFont systemFontOfSize:16]; [self.view addSubview:self.pubTextView]; UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.sectionInset = UIEdgeInsetsMake(0, 40, 10, 40); layout.itemSize = CGSizeMake(ScreenWidth/3 - 30, ScreenWidth/3 - 30); layout.minimumLineSpacing = 5; layout.minimumInteritemSpacing = 5; self.photoListView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.pubTextView.frame), ScreenWidth, ScreenWidth *2/3 - 50) collectionViewLayout:layout]; self.photoListView.delegate = self; self.photoListView.dataSource = self; self.photoListView.backgroundColor = [UIColor whiteColor]; [self.photoListView registerNib:[UINib nibWithNibName:@"PhotoCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([PhotoCollectionViewCell class])]; [self.view addSubview:self.photoListView]; } #pragma mark - - (void)handleSave { } - (void)handleCancel{ [self.navigationController popViewControllerAnimated:YES]; } - (void)handlePublish { if (self.pubTextView.text.length==0&&self.imageSource.count==0) { [MBProgressHUD showTextHUD:@"请输入动态内容" inView:self.view hideAfterDelay:1]; }else{ [self firstPublish]; } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ if (![self.pubTextView isExclusiveTouch]) { [self.pubTextView resignFirstResponder]; } } - (void)firstPublish{ NSString *str = [NSString stringWithFormat:@"%@modelInfo?action=doAddPrivate&ModelPK=%@&Intro=%@",imageURl,[ModelUser user].modelpk,self.pubTextView.text]; [[AHHttpManager sharedManager]POST:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(id responseObject) { NSLog(@"%@",responseObject); if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) { NSString *privatePk = [responseObject objectForKey:@"privatepk"]; if(self.imageSource.count==0){ [self.navigationController popViewControllerAnimated:YES]; }else{ [self haveImagePublish:privatePk]; } }else{ [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1]; } } failure:^(NSError *error) { NSLog(@"error = %@",error); [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1]; }]; } - (void)haveImagePublish:(NSString*)privatePk{ NSString * urlStr; for (int i=0; i *)info { UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"]; [picker dismissViewControllerAnimated:NO completion:nil]; [self postPicDataWithNetworkingWith:image]; } #pragma mark -- 上传图片 - (void)postPicDataWithNetworkingWith:(UIImage *)image { [MBProgressHUD showHUDAddedTo:self.view animated:YES]; [YanCNetWorkManager requestPostWithURLStr:Url_skillphoto(PublicUrl) fileData:image name:@"img" fileName:@"111.png" mimeType:@"image/jpg/png" parameters:nil finish:^(id dataDic) { [MBProgressHUD hideHUDForView:self.view animated:YES]; NSString *issuccess = dataDic[@"msg"]; if ([issuccess isEqualToString:@"success"]) { NSString *pubImageUrl = dataDic[@"img"]; [self.imageSource addObject:pubImageUrl]; [self.dataSource addObject:image]; [self.photoListView reloadData]; } else { [MBProgressHUD showInfo:@"请求失败!"]; } } enError:^(NSError *error) { [MBProgressHUD hideHUDForView:self.view animated:YES]; }]; } - (NSMutableArray *)dataSource { if (!_dataSource) { _dataSource = [NSMutableArray array]; } return _dataSource; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end