Commit bd40f854 authored by admin's avatar admin

图片自适应高度

parent 4d3c7d9d
......@@ -10,10 +10,10 @@
#define Url_h
// 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/"
......
......@@ -14,5 +14,5 @@
//@property (nonatomic, strong) UIButton *bigImageView;
@property (nonatomic, strong) UILabel *descriptionLabel;
@property (nonatomic, strong) NSLayoutConstraint *bigHeight;
@end
......@@ -8,7 +8,21 @@
#import "PictureTextTableCell.h"
@interface PictureTextTableCell ()
@property (nonatomic, assign) CGFloat bigH;
@end
@implementation PictureTextTableCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
_bigH = 170;
}
return self;
}
- (UIImageView *)bigImageView
{
if (!_bigImageView) {
......@@ -38,8 +52,12 @@
[self.contentView addConstraint:titleRight];
// 高度
NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_bigImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:170];
[self.contentView addConstraint:titleHeight];
// NSLayoutConstraint *titleHeight = [NSLayoutConstraint constraintWithItem:_bigImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:170];
// [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;
}
......
......@@ -17,4 +17,9 @@
@property (nonatomic, copy) NSString *lastModified;
@property (nonatomic, copy) NSString *uuid;
@property (nonatomic, copy) NSString *imageName;
@property (nonatomic, copy) NSString *describeStr;
@property (nonatomic, assign) BOOL isHavePic;
@end
......@@ -25,7 +25,7 @@
#import <UIImageView+WebCache.h>
#import <UIButton+WebCache.h>
#import <SDWebImageDownloader.h>
#define kPictureDetailTableCell @"PictureDetailTableViewCell"
#define kPictureTextTableCell @"PictureTextTableViewCell"
......@@ -46,6 +46,7 @@
@property (nonatomic, strong) NSMutableArray *imageNameArray;
@end
@implementation PictureStoryViewController
......@@ -70,6 +71,11 @@
[self setupNav];
_clickNumber = 0;
self.allCommentArray = [NSMutableArray array];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self requestPicturePraiseDetail];
}
......@@ -78,7 +84,6 @@
- (void)requestPicturePraiseDetail
{
self.allCommentArray = [NSMutableArray array];
NSString *user_uuid = [[NSUserDefaults standardUserDefaults] objectForKey:@"user_uuid"];
......@@ -102,20 +107,53 @@
}
for (NSDictionary *picTextDict in picDetail.attachments) {
PicTextModel *picText = [[PicTextModel alloc] init];
[picText setValuesForKeysWithDictionary:picTextDict];
[_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;
self.tableView.dataSource = self;
[MBProgressHUD hideHUDForView:self.view animated:YES];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}];
}
- (void)setupNav
{
UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
......@@ -137,9 +175,27 @@
-(void)doBack:(id)sender
{
[self clear];
[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
{
_clickNumber++;
......@@ -297,7 +353,6 @@
// cell显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
PictureDetailTableCell *cell=[tableView dequeueReusableCellWithIdentifier:kPictureDetailTableCell];
if (!cell) {
......@@ -347,30 +402,29 @@
if (!cell) {
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];
NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kRedStarURL ,picText.fileUrl]];
UIImage *defaultImage = [UIImage imageNamed:@"default_pic"];
[cell.bigImageView sd_setImageWithURL:imageUrl placeholderImage:defaultImage];
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 = @"";
if (image) {
if (picText.isHavePic) {
CGFloat bigImageH = (kScreenWidth - 40) / image.size.width * image.size.height;
cell.bigHeight.constant = bigImageH;
[cell.bigImageView layoutIfNeeded];
}
cell.bigImageView.image = image;
} 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;
}
} else {
// 评论
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