| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- //
- // ImageViewController.m
- // 千模
- //
- // Created by MUMEI on 2018/7/1.
- // Copyright © 2018年 MUMEI. All rights reserved.
- //
- #import "ImageViewController.h"
- #import "CustomTextField.h"
- @interface ImageViewController ()<UITextFieldDelegate>
- {
- UIImageView * inputImage;
- CustomTextField *textField;
- }
- @property (weak, nonatomic) IBOutlet UIImageView *Image;
- @property (weak, nonatomic) IBOutlet UIButton *dianZanBtn;
- @property (weak, nonatomic) IBOutlet UIButton *pingLunBtn;
- @property (weak, nonatomic) IBOutlet UILabel *dianZanLabel;
- @property (weak, nonatomic) IBOutlet UILabel *pingLunLabel;
- @property (weak, nonatomic) IBOutlet UIButton *dianZanBtn2;
- @property (weak, nonatomic) IBOutlet UIButton *pingLunBtn2;
- @property (weak, nonatomic) IBOutlet UILabel *dianZanNum;
- @property (weak, nonatomic) IBOutlet UILabel *pingLunNum;
- @property (weak, nonatomic) IBOutlet UILabel *introText;
- @property (weak, nonatomic) IBOutlet UIScrollView *scrollVIew;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *top;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottom;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *textBottom;
- @end
- @implementation ImageViewController
- {
- BOOL isZan;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.navigationItem.title = @"";
- self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#333333"] ;
- if ([UIScreen spt_currentScreenMode]== LESScreenModeIPhoneX) {
- _top.constant = -24;
- _bottom.constant = 34;
- _textBottom.constant = 25;
- }
-
- UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(0, 0, 40, 40);
- [btn setImage:[UIImage imageNamed:@"fanhui1"] forState:UIControlStateNormal];
- btn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
- [btn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
- UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
- UIBarButtonItem *nagetiveSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
- nagetiveSpacer.width = -12;//这个值可以根据自己需要自己调整
- self.navigationItem.leftBarButtonItems = @[nagetiveSpacer, leftItem];
- self.view.backgroundColor = [UIColor blackColor];
- [self set];
- UITapGestureRecognizer *Tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toDianZan:)];;
- [self.dianZanLabel addGestureRecognizer:Tap1];
- self.dianZanLabel.userInteractionEnabled = YES;
-
- UITapGestureRecognizer *Tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toPingLun:)];;
- [self.pingLunLabel addGestureRecognizer:Tap2];
- self.pingLunLabel.userInteractionEnabled = YES;
-
- inputImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, ScreenWidth+170, 400, 30)];
- [inputImage setImage:[UIImage imageNamed:@"pinglunshurukuang"]];
- inputImage.userInteractionEnabled = YES;
- inputImage.hidden = YES;
-
- textField = [[CustomTextField alloc]initWithFrame:CGRectMake(10, 0, 380, 30) placeholder:@"评论" clear:NO leftView:nil fontSize:17];
- textField.delegate = self;
- textField.layer.borderWidth = 1.0;
- textField.layer.borderColor = [UIColor clearColor].CGColor;
- textField.returnKeyType = UIReturnKeyDone;
-
- [self.view addSubview:inputImage];
- [inputImage addSubview:textField];
- if([_model.islikes isEqualToString:@"0"]){
- [_dianZanBtn setImage:[UIImage imageNamed:@"zan"] forState:UIControlStateNormal];
- isZan = NO;
- }else if ([_model.islikes isEqualToString:@"1"]){
- [_dianZanBtn setImage:[UIImage imageNamed:@"aixin"] forState:UIControlStateNormal];
- isZan = YES;
- }
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:NO animated:YES];
- }
- -(void)viewWillDisappear:(BOOL)animated{
- [super viewWillDisappear:animated];
- // self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"#FFFFFF"] ;
- }
- - (void)toDianZan:(UITapGestureRecognizer*)recognizer {
- [self dianZanEvent];
- }
- - (void)toPingLun:(UITapGestureRecognizer*)recognizer {
- [self pingLunEvent];
- }
- -(void)backClick{
- [self.navigationController popViewControllerAnimated:YES];
- }
- - (void)setModel:(PrivateModel *)model{
- _model = model;
- }
- - (void)set{
- self.introText.text = _model.intro;
- NSMutableArray * photo = _model.iteminfo;
- // [self.Image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imageURl,[photo[_i] objectForKey:@"url"]]]];
- NSMutableArray * dianZanArray = _model.privateInfo;
- self.dianZanNum.text = [NSString stringWithFormat:@"%ld",dianZanArray.count];
- NSLog(@"text = %lu ,%ld",(unsigned long)dianZanArray.count,dianZanArray.count);
- NSMutableArray * pingLunArray = _model.recordinfo;
- self.pingLunNum.text = [NSString stringWithFormat:@"%ld",pingLunArray.count];
- self.scrollVIew.contentSize = CGSizeMake(ScreenWidth*photo.count, 0);
- self.scrollVIew.showsHorizontalScrollIndicator = NO;
- self.scrollVIew.showsVerticalScrollIndicator = NO;
- self.scrollVIew.pagingEnabled = YES;
- for (int i=0; i<photo.count; i++) {
- UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(i*ScreenWidth, 0, ScreenWidth, ScreenWidth)];
- [image sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",imageURl,[photo[i]objectForKey:@"url"]]] placeholderImage:[UIImage imageNamed:@"jiazai"]];
- [self.scrollVIew addSubview:image];
- }
- [self.scrollVIew setContentOffset:CGPointMake(_i*ScreenWidth, 0) animated:YES];
- self.scrollVIew.bouncesZoom = NO;
- }
- -(void)scrollViewWillBeginDecelerating: (UIScrollView *)scrollView{
- [scrollView setContentOffset:scrollView.contentOffset animated:NO];
- }
- - (IBAction)clickDianzanButton:(UIButton *)sender {
- [self dianZanEvent];
- }
- - (IBAction)clickPinglunButton:(UIButton *)sender {
- [self pingLunEvent];
- }
- - (void)dianZanEvent{
- NSString *type = @"";
- if(!isZan){
- type = @"1";
- [_dianZanBtn setImage:[UIImage imageNamed:@"aixin"] forState:UIControlStateNormal];
- }else{
- type = @"2";
- [_dianZanBtn setImage:[UIImage imageNamed:@"zan"] forState:UIControlStateNormal];
- }
- isZan = !isZan;
- NSString *str = [NSString stringWithFormat:@"%@modelInfo?action=likes&memberPk=%@&privatePk=%@&type=%@",imageURl,[ModelUser user].pk,_model.privatepk,type];
- [[AHHttpManager sharedManager]POST:str parameters:nil success:^(id responseObject) {
- NSLog(@"%@",responseObject);
- if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) {
-
- }else{
- [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
- }
- } failure:^(NSError *error) {
- NSLog(@"error = %@",error);
- [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
- }];
- }
- - (void)pingLunEvent{
- inputImage.hidden = NO;
- [textField becomeFirstResponder];
- NSTimeInterval animationDuration = 0.30f;
- [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
- [UIView setAnimationDuration:animationDuration];
- // //将视图的Y坐标向上移动,以使下面腾出地方用于软键盘的显示
- // self.view.frame = CGRectMake(0.0f, -172.0f/*屏幕上移的高度,可以自己定*/, self.view.frame.size.width, self.view.frame.size.height);
- [UIView commitAnimations];
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField
- {
- //滑动效果
- NSTimeInterval animationDuration = 0.30f;
- [UIView beginAnimations:@ "ResizeForKeyboard" context:nil];
- [UIView setAnimationDuration:animationDuration];
- //恢复屏幕
- // self.view.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height);
- [UIView commitAnimations];
- inputImage.hidden = YES;
- }
- - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
- if (![inputImage isExclusiveTouch]) {
- [textField resignFirstResponder];
- }
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
- if (theTextField == textField) {
- [self addPinglun];
- [textField resignFirstResponder];
- }
- return YES;
- }
- - (void)addPinglun{
- if (textField.text.length==0) {
- [textField resignFirstResponder];
- }else{
- NSString *str = [NSString stringWithFormat:@"%@modelInfo?action=doAddPrivateRecord&PrivatePK=%@&PK=%@&RecordInfoPK=0&Intro=%@",imageURl,_model.privatepk,[Helper sharedAccount].accid,textField.text];
- NSLog(@"str = %@",str);
- [[AHHttpManager sharedManager]POST:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] parameters:nil success:^(id responseObject) {
- NSLog(@"%@",responseObject);
- if ([[responseObject objectForKey:@"msg"]isEqualToString:@"success"]) {
- [MBProgressHUD showTextHUD:@"添加评论成功" inView:self.view hideAfterDelay:1];
- }else{
- [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
- }
- } failure:^(NSError *error) {
- NSLog(@"error = %@",error);
- [MBProgressHUD showTextHUD:@"超时" inView:self.view hideAfterDelay:1];
- }];
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
|