ImageViewController.m 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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)viewWillDisappear:(BOOL)animated{
  80. [super viewWillDisappear:animated];
  81. // self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#FFFFFF"] ;
  82. }
  83. - (void)toDianZan:(UITapGestureRecognizer*)recognizer {
  84. [self dianZanEvent];
  85. }
  86. - (void)toPingLun:(UITapGestureRecognizer*)recognizer {
  87. [self pingLunEvent];
  88. }
  89. -(void)backClick{
  90. [self.navigationController popViewControllerAnimated:YES];
  91. }
  92. - (void)setModel:(PrivateModel *)model{
  93. _model = model;
  94. }
  95. - (void)set{
  96. self.introText.text = _model.intro;
  97. NSMutableArray * photo = _model.iteminfo;
  98. // [self.Image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imageURl,[photo[_i] objectForKey:@"url"]]]];
  99. NSMutableArray * dianZanArray = _model.privateInfo;
  100. self.dianZanNum.text = [NSString stringWithFormat:@"%ld",dianZanArray.count];
  101. NSLog(@"text = %lu ,%ld",(unsigned long)dianZanArray.count,dianZanArray.count);
  102. NSMutableArray * pingLunArray = _model.recordinfo;
  103. self.pingLunNum.text = [NSString stringWithFormat:@"%ld",pingLunArray.count];
  104. self.scrollVIew.contentSize = CGSizeMake(ScreenWidth*photo.count, 0);
  105. self.scrollVIew.showsHorizontalScrollIndicator = NO;
  106. self.scrollVIew.showsVerticalScrollIndicator = NO;
  107. self.scrollVIew.pagingEnabled = YES;
  108. for (int i=0; i<photo.count; i++) {
  109. UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(i*ScreenWidth, 0, ScreenWidth, ScreenWidth)];
  110. [image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imageURl,[photo[i]objectForKey:@"url"]]] placeholderImage:[UIImage imageNamed:@"jiazai"]];
  111. [self.scrollVIew addSubview:image];
  112. }
  113. [self.scrollVIew setContentOffset:CGPointMake(_i*ScreenWidth, 0) animated:YES];
  114. self.scrollVIew.bouncesZoom = NO;
  115. }
  116. -(void)scrollViewWillBeginDecelerating: (UIScrollView *)scrollView{
  117. [scrollView setContentOffset:scrollView.contentOffset animated:NO];
  118. }
  119. - (IBAction)clickDianzanButton:(UIButton *)sender {
  120. [self dianZanEvent];
  121. }
  122. - (IBAction)clickPinglunButton:(UIButton *)sender {
  123. [self pingLunEvent];
  124. }
  125. - (void)dianZanEvent{
  126. NSString *type = @"";
  127. if(!isZan){
  128. type = @"1";
  129. [_dianZanBtn setImage:[UIImage imageNamed:@"aixin"] forState:UIControlStateNormal];
  130. }else{
  131. type = @"2";
  132. [_dianZanBtn setImage:[UIImage imageNamed:@"zan"] forState:UIControlStateNormal];
  133. }
  134. isZan = !isZan;
  135. NSString *str = [NSString stringWithFormat:@"%@modelInfo?action=likes&memberPk=%@&privatePk=%@&type=%@",imageURl,[ModelUser user].pk,_model.privatepk,type];
  136. [[AHHttpManager sharedManager]POST:str parameters:nil success:^(id responseObject) {
  137. NSLog(@"%@",responseObject);
  138. if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) {
  139. }else{
  140. [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
  141. }
  142. } failure:^(NSError *error) {
  143. NSLog(@"error = %@",error);
  144. [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
  145. }];
  146. }
  147. - (void)pingLunEvent{
  148. inputImage.hidden = NO;
  149. [textField becomeFirstResponder];
  150. NSTimeInterval animationDuration = 0.30f;
  151. [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
  152. [UIView setAnimationDuration:animationDuration];
  153. // //将视图的Y坐标向上移动,以使下面腾出地方用于软键盘的显示
  154. // self.view.frame = CGRectMake(0.0f, -172.0f/*屏幕上移的高度,可以自己定*/, self.view.frame.size.width, self.view.frame.size.height);
  155. [UIView commitAnimations];
  156. }
  157. - (void)textFieldDidEndEditing:(UITextField *)textField
  158. {
  159. //滑动效果
  160. NSTimeInterval animationDuration = 0.30f;
  161. [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
  162. [UIView setAnimationDuration:animationDuration];
  163. //恢复屏幕
  164. // self.view.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height);
  165. [UIView commitAnimations];
  166. inputImage.hidden = YES;
  167. }
  168. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
  169. if (![inputImage isExclusiveTouch]) {
  170. [textField resignFirstResponder];
  171. }
  172. }
  173. - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
  174. if (theTextField == textField) {
  175. [self addPinglun];
  176. [textField resignFirstResponder];
  177. }
  178. return YES;
  179. }
  180. - (void)addPinglun{
  181. if (textField.text.length==0) {
  182. [textField resignFirstResponder];
  183. }else{
  184. NSString *str = [NSString stringWithFormat:@"%@modelInfo?action=doAddPrivateRecord&PrivatePK=%@&PK=%@&RecordInfoPK=0&Intro=%@",imageURl,_model.privatepk,[Helper sharedAccount].accid,textField.text];
  185. NSLog(@"str = %@",str);
  186. [[AHHttpManager sharedManager]POST:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(id responseObject) {
  187. NSLog(@"%@",responseObject);
  188. if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) {
  189. [MBProgressHUD showTextHUD:@"添加评论成功" inView:self.view hideAfterDelay:1];
  190. }else{
  191. [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
  192. }
  193. } failure:^(NSError *error) {
  194. NSLog(@"error = %@",error);
  195. [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
  196. }];
  197. }
  198. }
  199. - (void)didReceiveMemoryWarning {
  200. [super didReceiveMemoryWarning];
  201. // Dispose of any resources that can be recreated.
  202. }
  203. @end