ImageViewController.m 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. //
  2. // ImageViewController.m
  3. // 千模
  4. //
  5. // Created by MUMEI on 2018/7/1.
  6. // Copyright © 2018年 MUMEI. All rights reserved.
  7. //
  8. #import "ImageViewController.h"
  9. #import "CustomTextField.h"
  10. @interface ImageViewController ()<UITextFieldDelegate>
  11. {
  12. UIImageView * inputImage;
  13. CustomTextField *textField;
  14. }
  15. @property (weak, nonatomic) IBOutlet UIImageView *Image;
  16. @property (weak, nonatomic) IBOutlet UIButton *dianZanBtn;
  17. @property (weak, nonatomic) IBOutlet UIButton *pingLunBtn;
  18. @property (weak, nonatomic) IBOutlet UILabel *dianZanLabel;
  19. @property (weak, nonatomic) IBOutlet UILabel *pingLunLabel;
  20. @property (weak, nonatomic) IBOutlet UIButton *dianZanBtn2;
  21. @property (weak, nonatomic) IBOutlet UIButton *pingLunBtn2;
  22. @property (weak, nonatomic) IBOutlet UILabel *dianZanNum;
  23. @property (weak, nonatomic) IBOutlet UILabel *pingLunNum;
  24. @property (weak, nonatomic) IBOutlet UILabel *introText;
  25. @property (weak, nonatomic) IBOutlet UIScrollView *scrollVIew;
  26. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *top;
  27. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottom;
  28. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *textBottom;
  29. @end
  30. @implementation ImageViewController
  31. {
  32. BOOL isZan;
  33. }
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. self.navigationItem.title = @"";
  37. self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#333333"] ;
  38. if ([UIScreen spt_currentScreenMode]== LESScreenModeIPhoneX) {
  39. _top.constant = -24;
  40. _bottom.constant = 34;
  41. _textBottom.constant = 25;
  42. }
  43. UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
  44. btn.frame = CGRectMake(0, 0, 40, 40);
  45. [btn setImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];
  46. btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
  47. [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
  48. UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
  49. UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
  50. nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
  51. self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
  52. self.view.backgroundColor = [UIColor blackColor];
  53. [self set];
  54. UITapGestureRecognizer *Tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toDianZan:)];;
  55. [self.dianZanLabel addGestureRecognizer:Tap1];
  56. self.dianZanLabel.userInteractionEnabled = YES;
  57. UITapGestureRecognizer *Tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toPingLun:)];;
  58. [self.pingLunLabel addGestureRecognizer:Tap2];
  59. self.pingLunLabel.userInteractionEnabled = YES;
  60. inputImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, ScreenWidth+170, 400, 30)];
  61. [inputImage setImage:[UIImage imageNamed:@"pinglunshurukuang"]];
  62. inputImage.userInteractionEnabled = YES;
  63. inputImage.hidden = YES;
  64. textField = [[CustomTextField alloc]initWithFrame:CGRectMake(10, 0, 380, 30) placeholder:@"评论" clear:NO leftView:nil fontSize:17];
  65. textField.delegate = self;
  66. textField.layer.borderWidth = 1.0;
  67. textField.layer.borderColor = [UIColor clearColor].CGColor;
  68. textField.returnKeyType = UIReturnKeyDone;
  69. [self.view addSubview:inputImage];
  70. [inputImage addSubview:textField];
  71. if([_model.islikes isEqualToString:@"0"]){
  72. [_dianZanBtn setImage:[UIImage imageNamed:@"zan"] forState:UIControlStateNormal];
  73. isZan = NO;
  74. }else if ([_model.islikes isEqualToString:@"1"]){
  75. [_dianZanBtn setImage:[UIImage imageNamed:@"aixin"] forState:UIControlStateNormal];
  76. isZan = YES;
  77. }
  78. }
  79. - (void)viewWillAppear:(BOOL)animated{
  80. [super viewWillAppear:animated];
  81. [self.navigationController setNavigationBarHidden:NO animated:YES];
  82. }
  83. -(void)viewWillDisappear:(BOOL)animated{
  84. [super viewWillDisappear:animated];
  85. // self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#FFFFFF"] ;
  86. }
  87. - (void)toDianZan:(UITapGestureRecognizer*)recognizer {
  88. [self dianZanEvent];
  89. }
  90. - (void)toPingLun:(UITapGestureRecognizer*)recognizer {
  91. [self pingLunEvent];
  92. }
  93. -(void)backClick{
  94. [self.navigationController popViewControllerAnimated:YES];
  95. }
  96. - (void)setModel:(PrivateModel *)model{
  97. _model = model;
  98. }
  99. - (void)set{
  100. self.introText.text = _model.intro;
  101. NSMutableArray * photo = _model.iteminfo;
  102. // [self.Image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imageURl,[photo[_i] objectForKey:@"url"]]]];
  103. NSMutableArray * dianZanArray = _model.privateInfo;
  104. self.dianZanNum.text = [NSString stringWithFormat:@"%ld",dianZanArray.count];
  105. NSLog(@"text = %lu ,%ld",(unsigned long)dianZanArray.count,dianZanArray.count);
  106. NSMutableArray * pingLunArray = _model.recordinfo;
  107. self.pingLunNum.text = [NSString stringWithFormat:@"%ld",pingLunArray.count];
  108. self.scrollVIew.contentSize = CGSizeMake(ScreenWidth*photo.count, 0);
  109. self.scrollVIew.showsHorizontalScrollIndicator = NO;
  110. self.scrollVIew.showsVerticalScrollIndicator = NO;
  111. self.scrollVIew.pagingEnabled = YES;
  112. for (int i=0; i<photo.count; i++) {
  113. UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(i*ScreenWidth, 0, ScreenWidth, ScreenWidth)];
  114. [image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imageURl,[photo[i]objectForKey:@"url"]]] placeholderImage:[UIImage imageNamed:@"jiazai"]];
  115. [self.scrollVIew addSubview:image];
  116. }
  117. [self.scrollVIew setContentOffset:CGPointMake(_i*ScreenWidth, 0) animated:YES];
  118. self.scrollVIew.bouncesZoom = NO;
  119. }
  120. -(void)scrollViewWillBeginDecelerating: (UIScrollView *)scrollView{
  121. [scrollView setContentOffset:scrollView.contentOffset animated:NO];
  122. }
  123. - (IBAction)clickDianzanButton:(UIButton *)sender {
  124. [self dianZanEvent];
  125. }
  126. - (IBAction)clickPinglunButton:(UIButton *)sender {
  127. [self pingLunEvent];
  128. }
  129. - (void)dianZanEvent{
  130. NSString *type = @"";
  131. if(!isZan){
  132. type = @"1";
  133. [_dianZanBtn setImage:[UIImage imageNamed:@"aixin"] forState:UIControlStateNormal];
  134. }else{
  135. type = @"2";
  136. [_dianZanBtn setImage:[UIImage imageNamed:@"zan"] forState:UIControlStateNormal];
  137. }
  138. isZan = !isZan;
  139. NSString *str = [NSString stringWithFormat:@"%@modelInfo?action=likes&memberPk=%@&privatePk=%@&type=%@",imageURl,[ModelUser user].pk,_model.privatepk,type];
  140. [[AHHttpManager sharedManager]POST:str parameters:nil success:^(id responseObject) {
  141. NSLog(@"%@",responseObject);
  142. if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) {
  143. }else{
  144. [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
  145. }
  146. } failure:^(NSError *error) {
  147. NSLog(@"error = %@",error);
  148. [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
  149. }];
  150. }
  151. - (void)pingLunEvent{
  152. inputImage.hidden = NO;
  153. [textField becomeFirstResponder];
  154. NSTimeInterval animationDuration = 0.30f;
  155. [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
  156. [UIView setAnimationDuration:animationDuration];
  157. // //将视图的Y坐标向上移动,以使下面腾出地方用于软键盘的显示
  158. // self.view.frame = CGRectMake(0.0f, -172.0f/*屏幕上移的高度,可以自己定*/, self.view.frame.size.width, self.view.frame.size.height);
  159. [UIView commitAnimations];
  160. }
  161. - (void)textFieldDidEndEditing:(UITextField *)textField
  162. {
  163. //滑动效果
  164. NSTimeInterval animationDuration = 0.30f;
  165. [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
  166. [UIView setAnimationDuration:animationDuration];
  167. //恢复屏幕
  168. // self.view.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height);
  169. [UIView commitAnimations];
  170. inputImage.hidden = YES;
  171. }
  172. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  173. if (![inputImage isExclusiveTouch]) {
  174. [textField resignFirstResponder];
  175. }
  176. }
  177. - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
  178. if (theTextField == textField) {
  179. [self addPinglun];
  180. [textField resignFirstResponder];
  181. }
  182. return YES;
  183. }
  184. - (void)addPinglun{
  185. if (textField.text.length==0) {
  186. [textField resignFirstResponder];
  187. }else{
  188. NSString *str = [NSString stringWithFormat:@"%@modelInfo?action=doAddPrivateRecord&PrivatePK=%@&PK=%@&RecordInfoPK=0&Intro=%@",imageURl,_model.privatepk,[Helper sharedAccount].accid,textField.text];
  189. NSLog(@"str = %@",str);
  190. [[AHHttpManager sharedManager]POST:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(id responseObject) {
  191. NSLog(@"%@",responseObject);
  192. if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) {
  193. [MBProgressHUD showTextHUD:@"添加评论成功" inView:self.view hideAfterDelay:1];
  194. }else{
  195. [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
  196. }
  197. } failure:^(NSError *error) {
  198. NSLog(@"error = %@",error);
  199. [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
  200. }];
  201. }
  202. }
  203. - (void)didReceiveMemoryWarning {
  204. [super didReceiveMemoryWarning];
  205. // Dispose of any resources that can be recreated.
  206. }
  207. @end