Commit bd40f854 authored by admin's avatar admin

图片自适应高度

parent 4d3c7d9d
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
#define Url_h #define Url_h
// url 测试环境 // url 测试环境
#define kRedStarURL @"http://218.244.151.129:7580/" // #define kRedStarURL @"http://218.244.151.129:7580/"
// 正式环境 // 正式环境
// #define kRedStarURL @"http://219.235.234.225:7580/" #define kRedStarURL @"http://219.235.234.225:7580/"
// 最新正式环境 // 最新正式环境
// #define kRedStarURL @"http://219.235.234.212:7580/" // #define kRedStarURL @"http://219.235.234.212:7580/"
......
...@@ -14,5 +14,5 @@ ...@@ -14,5 +14,5 @@
//@property (nonatomic, strong) UIButton *bigImageView; //@property (nonatomic, strong) UIButton *bigImageView;
@property (nonatomic, strong) UILabel *descriptionLabel; @property (nonatomic, strong) UILabel *descriptionLabel;
@property (nonatomic, strong) NSLayoutConstraint *bigHeight;
@end @end
...@@ -8,7 +8,21 @@ ...@@ -8,7 +8,21 @@
#import "PictureTextTableCell.h" #import "PictureTextTableCell.h"
@interface PictureTextTableCell ()
@property (nonatomic, assign) CGFloat bigH;
@end
@implementation PictureTextTableCell @implementation PictureTextTableCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
_bigH = 170;
}
return self;
}
- (UIImageView *)bigImageView - (UIImageView *)bigImageView
{ {
if (!_bigImageView) { if (!_bigImageView) {
...@@ -38,8 +52,12 @@ ...@@ -38,8 +52,12 @@
[self.contentView addConstraint:titleRight]; [self.contentView addConstraint:titleRight];
// 高度 // 高度
NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_bigImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:170]; // NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_bigImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:170];
[self.contentView addConstraint:titleHeight]; // [self.contentView addConstraint:titleHeight];
self.bigHeight = [NSLayoutConstraint constraintWithItem:_bigImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:_bigH];
[self.contentView addConstraint:_bigHeight];
} }
return _bigImageView; return _bigImageView;
} }
......
...@@ -17,4 +17,9 @@ ...@@ -17,4 +17,9 @@
@property (nonatomic, copy) NSString *lastModified; @property (nonatomic, copy) NSString *lastModified;
@property (nonatomic, copy) NSString *uuid; @property (nonatomic, copy) NSString *uuid;
@property (nonatomic, copy) NSString *imageName;
@property (nonatomic, copy) NSString *describeStr;
@property (nonatomic, assign) BOOL isHavePic;
@end @end
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#import <UIImageView+WebCache.h> #import <UIImageView+WebCache.h>
#import <UIButton+WebCache.h> #import <UIButton+WebCache.h>
#import <SDWebImageDownloader.h>
#define kPictureDetailTableCell @"PictureDetailTableViewCell" #define kPictureDetailTableCell @"PictureDetailTableViewCell"
#define kPictureTextTableCell @"PictureTextTableViewCell" #define kPictureTextTableCell @"PictureTextTableViewCell"
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
@property (nonatomic, strong) NSMutableArray *imageNameArray; @property (nonatomic, strong) NSMutableArray *imageNameArray;
@end @end
@implementation PictureStoryViewController @implementation PictureStoryViewController
...@@ -70,6 +71,11 @@ ...@@ -70,6 +71,11 @@
[self setupNav]; [self setupNav];
_clickNumber = 0; _clickNumber = 0;
self.allCommentArray = [NSMutableArray array];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self requestPicturePraiseDetail]; [self requestPicturePraiseDetail];
} }
...@@ -78,7 +84,6 @@ ...@@ -78,7 +84,6 @@
- (void)requestPicturePraiseDetail - (void)requestPicturePraiseDetail
{ {
self.allCommentArray = [NSMutableArray array];
NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"]; NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
...@@ -102,20 +107,53 @@ ...@@ -102,20 +107,53 @@
} }
for (NSDictionary *picTextDict in picDetail.attachments) { for (NSDictionary *picTextDict in picDetail.attachments) {
PicTextModel *picText = [[PicTextModel alloc] init]; PicTextModel *picText = [[PicTextModel alloc] init];
[picText setValuesForKeysWithDictionary:picTextDict]; [picText setValuesForKeysWithDictionary:picTextDict];
[_picTextArray addObject:picText]; [_picTextArray addObject:picText];
NSString *imageUrl = [NSString stringWithFormat:@"%@%@", kRedStarURL, picTextDict[@"fileUrl"]];
[[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:imageUrl] options:SDWebImageDownloaderUseNSURLCache progress:nil completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
picText.isHavePic = finished;
NSString *imageName = nil;
if (image == nil) {
imageName = @"";
} else {
imageName = [CommonFunc md5Data:data];
NSString *fullPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", imageName]];
[_imageNameArray addObject:imageName];
[data writeToFile:fullPath atomically:NO];
}
NSString *describe = nil;
if ([picTextDict[@"description"] isEqual:[NSNull null]]) {
describe = @"";
} else {
describe = [NSString stringWithFormat:@"%@",picTextDict[@"description"]];
}
picText.describeStr = describe;
picText.imageName = imageName;
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}];
} }
//
self.tableView.delegate = self; [MBProgressHUD hideHUDForView:self.view animated:YES];
self.tableView.dataSource = self;
[MBProgressHUD hideHUDForView:self.view animated:YES];
}]; }];
} }
- (void)setupNav - (void)setupNav
{ {
UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)]; UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
...@@ -137,9 +175,27 @@ ...@@ -137,9 +175,27 @@
-(void)doBack:(id)sender -(void)doBack:(id)sender
{ {
[self clear];
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
} }
- (void)clear
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *fullPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];
for (NSString *p in _imageNameArray) {
NSError *error;
NSString *path = [fullPath stringByAppendingPathComponent:p];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
}
}
});
}
- (void)addZan:(ZanButton *)sender - (void)addZan:(ZanButton *)sender
{ {
_clickNumber++; _clickNumber++;
...@@ -297,7 +353,6 @@ ...@@ -297,7 +353,6 @@
// cell显示的内容 // cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ {
if (indexPath.section == 0) { if (indexPath.section == 0) {
PictureDetailTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kPictureDetailTableCell]; PictureDetailTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kPictureDetailTableCell];
if (!cell) { if (!cell) {
...@@ -347,30 +402,29 @@ ...@@ -347,30 +402,29 @@
if (!cell) { if (!cell) {
cell = [[PictureTextTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kPictureTextTableCell]; cell = [[PictureTextTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kPictureTextTableCell];
} }
NSString *imageName = picText.imageName;
NSString *fullPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", imageName]];
UIImage *image = [UIImage imageWithContentsOfFile:fullPath];
if (image) {
if (picText.isHavePic) {
NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kRedStarURL ,picText.fileUrl]]; CGFloat bigImageH = (kScreenWidth - 40) / image.size.width * image.size.height;
cell.bigHeight.constant = bigImageH;
UIImage *defaultImage = [UIImage imageNamed:@"default_pic"]; [cell.bigImageView layoutIfNeeded];
}
[cell.bigImageView sd_setImageWithURL:imageUrl placeholderImage:defaultImage]; cell.bigImageView.image = image;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
[cell.bigImageView addGestureRecognizer:tap];
NSString *str = [NSString stringWithFormat:@"%@", picText.descriptionText];
if (picText.descriptionText == nil || picText.descriptionText == NULL || [picText.descriptionText isEqual:[NSNull null]]) {
cell.descriptionLabel.text = @"";
} else { } else {
cell.descriptionLabel.text = str; cell.bigImageView.image = [UIImage imageNamed:@"default_pic"];
} }
cell.selectionStyle = UITableViewCellSelectionStyleNone; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
[cell.bigImageView addGestureRecognizer:tap];
cell.descriptionLabel.text = picText.describeStr;
return cell; return cell;
} }
} else { } else {
// 评论 // 评论
PictureCommentTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kPictureCommentTableCell]; PictureCommentTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kPictureCommentTableCell];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment