diff --git a/Class/LearningCenter/ComprehensiveDiscussion/Cells/CommentListTableViewCell.m b/Class/LearningCenter/ComprehensiveDiscussion/Cells/CommentListTableViewCell.m index 9088a6849da7b7779699b07d65e44edf20f60c17..70edcc7422864ab8374d5ed1d1df89dad96053b7 100644 --- a/Class/LearningCenter/ComprehensiveDiscussion/Cells/CommentListTableViewCell.m +++ b/Class/LearningCenter/ComprehensiveDiscussion/Cells/CommentListTableViewCell.m @@ -7,7 +7,10 @@ // #import "CommentListTableViewCell.h" - +#import "MWPhotoBrowser.h" +@interface CommentListTableViewCell ()<MWPhotoBrowserDelegate> +@property (nonatomic,strong) NSMutableArray *browserArray; +@end @implementation CommentListTableViewCell - (void)awakeFromNib { @@ -23,6 +26,7 @@ for (UIImageView *obj in self.attachmentView.subviews) { if ([obj isKindOfClass:[UIImageView class]]) { + obj.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)]; [obj addGestureRecognizer:tap]; } @@ -30,7 +34,38 @@ } - (void)tapImage:(UIGestureRecognizer *)tap { - NSLog(@"%lu", tap.view.tag); + if (tap.view.tag + 1 > self.replyEntity.attachments.count) { + return; + } + + [self.browserArray removeAllObjects]; + for (TOAttachmentEntity *att in self.replyEntity.attachments) { + MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:att.fileUrl]]; + [self.browserArray addObject:photo]; + } + MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self]; + [browser setCurrentPhotoIndex:tap.view.tag]; + UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:browser]; + [self.viewController.navigationController presentViewController:nav animated:YES completion:nil]; +} + +#pragma mark - <MWPhotoBrowserDelegate> +- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser +{ + return self.browserArray.count; +} + +- (id<MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index +{ + if (index < self.browserArray.count) { + return [self.browserArray objectAtIndex:index]; + } + return nil; +} + +- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index +{ + return [NSString stringWithFormat:@"%ld/%ld", index + 1, self.browserArray.count]; } #pragma mark - 选项按钮 - (IBAction)extensionButtonClickAction:(UIButton *)sender { @@ -59,6 +94,26 @@ self.bestView.isBest = _replyEntity.best; self.bestView.indexPath = self.indexPath; self.baseImageView.hidden = !_replyEntity.best; + if (replyEntity.attachments.count > 0) { + self.layoutAttHeight.constant = 164; + }else{ + self.layoutAttHeight.constant = 0; + } + + for (NSInteger i = 0; i < replyEntity.attachments.count; i++) { + TOAttachmentEntity *att = replyEntity.attachments[i]; + UIImageView *imgView = (UIImageView *)[self.attachmentView viewWithTag:i]; + [imgView sd_setImageWithURL:[NSURL URLWithString:att.fileUrl] placeholderImage:REPLACEIMAGE]; + } +} + +#pragma mark - lazy +- (NSMutableArray *)browserArray +{ + if (!_browserArray) { + _browserArray = [NSMutableArray array]; + } + return _browserArray; } @end diff --git a/Class/LearningCenter/ComprehensiveDiscussion/Controllers/ForumItemDetailViewController.m b/Class/LearningCenter/ComprehensiveDiscussion/Controllers/ForumItemDetailViewController.m index 908f37d842dac19fdd87bdb7901ae673f368c38b..99157dfa3e4b60d0a8292f31b55a7409b23bcc21 100644 --- a/Class/LearningCenter/ComprehensiveDiscussion/Controllers/ForumItemDetailViewController.m +++ b/Class/LearningCenter/ComprehensiveDiscussion/Controllers/ForumItemDetailViewController.m @@ -16,6 +16,8 @@ #import "ZJKeyBoardAccessoryView.h" #import "ForumDetailBottomView.h" #import "OSSHelper.h" +#import "ForumCommentListViewModel.h" +#import "UIImage+Helper.h" @interface ForumItemDetailViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,TapClickDelegate,ReturnTableviewcellIndexpathdelegate> @@ -170,7 +172,12 @@ weakSelf.commentsArray = nil; } weakSelf.topicReply = [[ForumReplyResponse alloc] initWithDictionary:RESPONSE(returnValue) error:nil]; - [weakSelf.commentsArray addObjectsFromArray:weakSelf.topicReply.forumReplyEntity]; + for (CustomTOForumReplyEntity *entity in weakSelf.topicReply.forumReplyEntity) { + ForumCommentListViewModel *model = [ForumCommentListViewModel new]; + model.replyEntity = entity; + [weakSelf.commentsArray addObject:model]; + + } [weakSelf setUpCommentNumber]; [weakSelf.forumDetailTableView reloadData]; }else { @@ -230,7 +237,8 @@ CommentListTableViewCell *commentCell = [tableView dequeueReusableCellWithIdentifier:@"CommentListTableViewCell" forIndexPath:indexPath]; commentCell.bestView.delegate = self; commentCell.indexPath = indexPath; - commentCell.replyEntity = self.commentsArray[indexPath.row]; + ForumCommentListViewModel *cellModel = self.commentsArray[indexPath.row]; + commentCell.replyEntity = cellModel.replyEntity; BOOL boolValue = ([self.topicDetail.posterId isEqualToString:[Shoppersmanager manager].shoppers.employee.fid] && [self.category.name isEqualToString:OPPLE_ASK]); commentCell.optionButton.hidden = !boolValue; return commentCell; @@ -256,9 +264,9 @@ } break; } - CustomTOForumReplyEntity *replyEntity = self.commentsArray[indexPath.row]; + ForumCommentListViewModel *cellModel = self.commentsArray[indexPath.row]; //68ä¸ºä¸Šè¾¹è· 10ä¸ºä¸‹è¾¹è· - return replyEntity.replyContentHeight + 68 + 10; + return cellModel.height; } - (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath @@ -309,10 +317,13 @@ #pragma mark - ä¸Šä¼ å›¾ç‰‡é™„ä»¶ - (void)uploadAttachments:(void(^)(NSArray *OSSKeys))finish { - + if (self.bottomView.toolView.arrSelectedPhotos.count == 0) { + finish(nil); + return; + } NSMutableArray *OSSKeyArray = [NSMutableArray array]; for (int i=0; i<self.bottomView.toolView.arrSelectedPhotos.count; i++) { - [OSSKeyArray addObject:[OSSHelper getOSSObjectKeyWithtype:@"png" index:i]]; + [OSSKeyArray addObject:[OSSHelper getOSSObjectKeyWithtype:@"jpg" index:i]]; } XBLoadingView *loadView = [XBLoadingView showHUDViewProgressLabel:[NSString stringWithFormat:@"å›¾ç‰‡ä¸Šä¼ ä¸:1/%ld",self.bottomView.toolView.arrSelectedPhotos.count]]; static NSInteger number = 0; @@ -321,7 +332,8 @@ for (int i=0;i<self.bottomView.toolView.arrSelectedPhotos.count;i++) { UIImage *image = self.bottomView.toolView.arrSelectedPhotos[i]; NSString *ossKey = OSSKeyArray[i]; - NSData *data = UIImagePNGRepresentation(image); + UIImage *newSizeImage = [image scaledToWidth:1024]; + NSData *data = [newSizeImage scaledToSpaceMaxSize:200]; [OSSHelper uploadImageObjectWithKey:ossKey data:data type:OSSHelperOperationTypeSynchronous progress:^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) { CGFloat totalBytesSentFloat = totalBytesSent; CGFloat totalBytesExpectedToSendFloat = totalBytesExpectedToSend; @@ -394,6 +406,7 @@ [XBLoadingView hideHUDViewWithDefault]; if (RESULT(returnValue)) { weakSelf.commentInputTextFieldView.text = nil; + [weakSelf.bottomView clearPhoto]; [XBLoadingView showHUDViewWithSuccessText:@"评论æˆåŠŸ" completeBlock:^{ if (weakSelf.refreshBlock) { weakSelf.refreshBlock(ONE,Comment,weakSelf.indexPath); diff --git a/Class/LearningCenter/ComprehensiveDiscussion/ViewModels/ForumCommentListViewModel.h b/Class/LearningCenter/ComprehensiveDiscussion/ViewModels/ForumCommentListViewModel.h new file mode 100644 index 0000000000000000000000000000000000000000..f9e6258968764dad2ec3f5a5a5a110b411723622 --- /dev/null +++ b/Class/LearningCenter/ComprehensiveDiscussion/ViewModels/ForumCommentListViewModel.h @@ -0,0 +1,18 @@ +// +// ForumCommentListViewModel.h +// Lighting +// +// Created by Javen on 2017/4/18. +// Copyright © 2017å¹´ 上海勾芒科技有é™å…¬å¸. All rights reserved. +// + +#import <Foundation/Foundation.h> + +@interface ForumCommentListViewModel : NSObject +/** + å›žå¤æ•°æ®æº + */ +@property (nonatomic,strong) CustomTOForumReplyEntity *replyEntity; + +@property (nonatomic, assign) CGFloat height; +@end diff --git a/Class/LearningCenter/ComprehensiveDiscussion/ViewModels/ForumCommentListViewModel.m b/Class/LearningCenter/ComprehensiveDiscussion/ViewModels/ForumCommentListViewModel.m new file mode 100644 index 0000000000000000000000000000000000000000..25b98e1c19deb597a2dabf8d17af1bb9398bca3c --- /dev/null +++ b/Class/LearningCenter/ComprehensiveDiscussion/ViewModels/ForumCommentListViewModel.m @@ -0,0 +1,31 @@ +// +// ForumCommentListViewModel.m +// Lighting +// +// Created by Javen on 2017/4/18. +// Copyright © 2017å¹´ 上海勾芒科技有é™å…¬å¸. All rights reserved. +// + +#import "ForumCommentListViewModel.h" +static UILabel *stringLabel = nil; +@implementation ForumCommentListViewModel + +- (void)setReplyEntity:(CustomTOForumReplyEntity *)replyEntity { + _replyEntity = replyEntity; + self.height = 88; + if (replyEntity.attachments.count > 0) { + self.height = 88 + 164; + } + + + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ //生æˆä¸€ä¸ªç”¨äºŽè®¡ç®—文本高度的label + stringLabel = [[UILabel alloc] init]; + stringLabel.font = [UIFont systemFontOfSize:17]; + stringLabel.numberOfLines = 0; + }); + stringLabel.text = replyEntity.replyContent; + self.height = self.height + [stringLabel sizeThatFits:CGSizeMake(ScreenWidth - 40, MAXFLOAT)].height + 16; + NSLog(@"%f", self.height); +} +@end diff --git a/Class/LearningCenter/ComprehensiveDiscussion/Views/ForumDetailBottomView.h b/Class/LearningCenter/ComprehensiveDiscussion/Views/ForumDetailBottomView.h index dc3d19074c4622d870cc7e2df77f5670ac781166..1b258e611fc5d4801b86f46cfa4b4ca4b738bee2 100644 --- a/Class/LearningCenter/ComprehensiveDiscussion/Views/ForumDetailBottomView.h +++ b/Class/LearningCenter/ComprehensiveDiscussion/Views/ForumDetailBottomView.h @@ -16,4 +16,6 @@ */ @property (strong, nonatomic) ZJKeyBoardAccessoryView *toolView; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *layoutHeight; + +- (void)clearPhoto; @end diff --git a/Class/LearningCenter/ComprehensiveDiscussion/Views/ForumDetailBottomView.m b/Class/LearningCenter/ComprehensiveDiscussion/Views/ForumDetailBottomView.m index 737dbd62b8dc17c29e03c4950fa15fd487acbb5b..988ba957c5c2f134c94d764ee83fd8d0b1298bf6 100644 --- a/Class/LearningCenter/ComprehensiveDiscussion/Views/ForumDetailBottomView.m +++ b/Class/LearningCenter/ComprehensiveDiscussion/Views/ForumDetailBottomView.m @@ -54,6 +54,10 @@ return cell; } +- (void)clearPhoto { + [self.toolView deleteAll]; +} + /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. diff --git a/Class/LearningCenter/ComprehensiveDiscussion/Views/ZJKeyBoardAccessoryView.h b/Class/LearningCenter/ComprehensiveDiscussion/Views/ZJKeyBoardAccessoryView.h index 3803691c4dc8ee9061826966cf8d25a8533e552c..69f2a13341859eae367219da74573c38efd9e45a 100644 --- a/Class/LearningCenter/ComprehensiveDiscussion/Views/ZJKeyBoardAccessoryView.h +++ b/Class/LearningCenter/ComprehensiveDiscussion/Views/ZJKeyBoardAccessoryView.h @@ -13,5 +13,15 @@ @property (strong, nonatomic) NSMutableArray *arrSelectedPhotos; @property (nonatomic, copy) void (^blockFinishSelected)(void); +/** + åˆ é™¤æŒ‡å®šä¸‹æ ‡çš„å›¾ç‰‡ + + @param index ä¸‹æ ‡ + */ - (void)deletePhotoWithIndex:(NSInteger)index; + +/** + åˆ é™¤æ‰€æœ‰çš„å›¾ç‰‡ + */ +- (void)deleteAll; @end diff --git a/Class/LearningCenter/ComprehensiveDiscussion/Views/ZJKeyBoardAccessoryView.m b/Class/LearningCenter/ComprehensiveDiscussion/Views/ZJKeyBoardAccessoryView.m index 3c6dfe5941286c4c2eb2a9b0627a5a68ef389d39..8e6907e7a58221b8814608e5a058fb18efb67714 100644 --- a/Class/LearningCenter/ComprehensiveDiscussion/Views/ZJKeyBoardAccessoryView.m +++ b/Class/LearningCenter/ComprehensiveDiscussion/Views/ZJKeyBoardAccessoryView.m @@ -28,7 +28,7 @@ typedef NS_ENUM(NSInteger, ItemIndex) { @property (strong, nonatomic) NSMutableArray *allPhotoArray; /** - <#Description#> + */ @property (strong, nonatomic) NSMutableArray *mwPhotoArray; @@ -36,6 +36,7 @@ typedef NS_ENUM(NSInteger, ItemIndex) { 缩略图 */ @property (strong, nonatomic) NSMutableArray *thumbsArray; +@property (strong, nonatomic) NSMutableDictionary *cache; @end @implementation ZJKeyBoardAccessoryView @@ -100,10 +101,14 @@ typedef NS_ENUM(NSInteger, ItemIndex) { #pragma mark - <UIImagePickerControllerDelegate> - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info { - // [self.navigationController dismissViewControllerAnimated:YES completion:nil]; + [picker dismissViewControllerAnimated:YES completion:nil]; UIImage *headImage = [info objectForKey:UIImagePickerControllerOriginalImage]; // [self.selectedImageArray addObject:headImage]; // [self.publishTableView reloadData]; + [self.arrSelectedPhotos addObject:headImage]; + if (self.blockFinishSelected) { + self.blockFinishSelected(); + } } #pragma mark - 相册选择照片 @@ -132,11 +137,31 @@ typedef NS_ENUM(NSInteger, ItemIndex) { - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index selectedChanged:(BOOL)selected { PHAsset *currentPhoto = self.allPhotoArray[index]; + + if (selected) { - [self.arrSelectedAssets addObject:currentPhoto]; - } else { + PHImageManager *imageManager = [PHImageManager defaultManager]; + PHImageRequestOptions *options = [PHImageRequestOptions new]; + options.networkAccessAllowed = YES; + options.resizeMode = PHImageRequestOptionsResizeModeFast; + options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; + options.synchronous = YES; + WS(weakSelf); + [imageManager requestImageForAsset:currentPhoto + targetSize:CGSizeMake(ScreenWidth, ScreenHeight) + contentMode:PHImageContentModeAspectFit + options:options + resultHandler:^(UIImage *result, NSDictionary *info) { + [self.arrSelectedAssets addObject:currentPhoto]; + [weakSelf.arrSelectedPhotos addObject:result]; + [weakSelf.cache setObject:result forKey:currentPhoto]; + }]; + }else{ + id result = [self.cache objectForKey:currentPhoto]; [self.arrSelectedAssets removeObject:currentPhoto]; + [self.arrSelectedPhotos removeObject:result]; } + } - (void)photoBrowserDidFinishModalPresentation:(MWPhotoBrowser *)photoBrowser { @@ -144,24 +169,24 @@ typedef NS_ENUM(NSInteger, ItemIndex) { [XBLoadingView showHUDViewWithText:@"图片最多选择3å¼ "]; return; } - - PHImageManager *imageManager = [PHImageManager defaultManager]; - PHImageRequestOptions *options = [PHImageRequestOptions new]; - options.networkAccessAllowed = YES; - options.resizeMode = PHImageRequestOptionsResizeModeFast; - options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; - options.synchronous = YES; - WS(weakSelf); - [self.arrSelectedPhotos removeAllObjects]; - for (PHAsset *asset in self.arrSelectedAssets) { - [imageManager requestImageForAsset:asset - targetSize:CGSizeMake(ScreenWidth, ScreenHeight) - contentMode:PHImageContentModeAspectFit - options:options - resultHandler:^(UIImage *result, NSDictionary *info){ - [weakSelf.arrSelectedPhotos addObject:result]; - }]; - } +// +// PHImageManager *imageManager = [PHImageManager defaultManager]; +// PHImageRequestOptions *options = [PHImageRequestOptions new]; +// options.networkAccessAllowed = YES; +// options.resizeMode = PHImageRequestOptionsResizeModeFast; +// options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; +// options.synchronous = YES; +// WS(weakSelf); +// [self.arrSelectedPhotos removeAllObjects]; +// for (PHAsset *asset in self.arrSelectedAssets) { +// [imageManager requestImageForAsset:asset +// targetSize:CGSizeMake(ScreenWidth, ScreenHeight) +// contentMode:PHImageContentModeAspectFit +// options:options +// resultHandler:^(UIImage *result, NSDictionary *info) { +// [weakSelf.arrSelectedPhotos addObject:result]; +// }]; +// } if (self.blockFinishSelected) { self.blockFinishSelected(); @@ -172,7 +197,12 @@ typedef NS_ENUM(NSInteger, ItemIndex) { } - (void)selectAlbumImage { - + if (![BaseViewController determinePhotosPermissions]) { + UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"æç¤º" message:@"请在iPad的“设置-éšç§-相册â€é€‰é¡¹ä¸ï¼Œå…è®¸æ¬§ç«‹æ–¹è®¿é—®ä½ çš„ç›¸å†Œ" preferredStyle:UIAlertControllerStyleAlert]; + [alertVC addAction:[UIAlertAction actionWithTitle:@"知é“了" style:UIAlertActionStyleCancel handler:nil]]; + [self.viewController presentViewController:alertVC animated:YES completion:nil]; + return; + } MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self]; browser.displayActionButton = YES; browser.displayNavArrows = YES; @@ -186,10 +216,34 @@ typedef NS_ENUM(NSInteger, ItemIndex) { [self.viewController.navigationController presentViewController:nav animated:YES completion:nil]; } - - (void)deletePhotoWithIndex:(NSInteger)index { - [self.arrSelectedAssets removeObjectAtIndex:index]; - [self.arrSelectedPhotos removeObjectAtIndex:index]; + UIImage *image = self.arrSelectedPhotos[index]; + + //如果è¦åˆ 除的照片在缓å˜é‡Œé¢ï¼Œé‚£ä¹ˆè¿™æ˜¯ç›¸å†Œé€‰æ‹©çš„照片,需è¦ä»Žç¼“å˜åˆ 除 + for (PHAsset *key in self.cache.allKeys) { + UIImage *cacheImage = [self.cache objectForKey:key]; + if ([cacheImage isEqual:image]) { + [self.cache removeObjectForKey:key]; + [self.arrSelectedAssets removeObject:key]; + break; + } + } + + [self.arrSelectedPhotos removeObject:image]; + + + if (self.blockFinishSelected) { + self.blockFinishSelected(); + } +} + +/** + åˆ é™¤æ‰€æœ‰çš„å›¾ç‰‡ + */ +- (void)deleteAll { + [self.arrSelectedAssets removeAllObjects]; + [self.arrSelectedPhotos removeAllObjects]; + [self.cache removeAllObjects]; if (self.blockFinishSelected) { self.blockFinishSelected(); } @@ -233,6 +287,13 @@ typedef NS_ENUM(NSInteger, ItemIndex) { return _arrSelectedPhotos; } +- (NSDictionary *)cache { + if (!_cache) { + _cache = [NSMutableDictionary dictionary]; + } + return _cache; +} + /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. diff --git a/Lighting.xcodeproj/project.pbxproj b/Lighting.xcodeproj/project.pbxproj index cf5408325f6989d38eeefa4fb94c542b1f379544..c3a868258ea3d0ccfb7cfd668ff2ab28f7d76c92 100644 --- a/Lighting.xcodeproj/project.pbxproj +++ b/Lighting.xcodeproj/project.pbxproj @@ -338,6 +338,8 @@ 8F0FD1A11EA48EC500D38035 /* ForumDetailBottomView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F0FD1A01EA48EC500D38035 /* ForumDetailBottomView.m */; }; 8F0FD1A41EA494EA00D38035 /* ForumDetailBottomPictureCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F0FD1A31EA494EA00D38035 /* ForumDetailBottomPictureCell.m */; }; 8F0FD1A71EA4A8BF00D38035 /* ZJKeyBoardAccessoryView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F0FD1A61EA4A8BF00D38035 /* ZJKeyBoardAccessoryView.m */; }; + 8F7B45461EA61FED00E52092 /* ForumCommentListViewModel.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F7B45451EA61FED00E52092 /* ForumCommentListViewModel.m */; }; + 8FEF03F31EA7543F00837A64 /* UIImage+Helper.m in Sources */ = {isa = PBXBuildFile; fileRef = 8FEF03F21EA7543F00837A64 /* UIImage+Helper.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -985,6 +987,10 @@ 8F0FD1A31EA494EA00D38035 /* ForumDetailBottomPictureCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ForumDetailBottomPictureCell.m; sourceTree = "<group>"; }; 8F0FD1A51EA4A8BF00D38035 /* ZJKeyBoardAccessoryView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ZJKeyBoardAccessoryView.h; sourceTree = "<group>"; }; 8F0FD1A61EA4A8BF00D38035 /* ZJKeyBoardAccessoryView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ZJKeyBoardAccessoryView.m; sourceTree = "<group>"; }; + 8F7B45441EA61FED00E52092 /* ForumCommentListViewModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ForumCommentListViewModel.h; sourceTree = "<group>"; }; + 8F7B45451EA61FED00E52092 /* ForumCommentListViewModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ForumCommentListViewModel.m; sourceTree = "<group>"; }; + 8FEF03F11EA7543F00837A64 /* UIImage+Helper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Helper.h"; sourceTree = "<group>"; }; + 8FEF03F21EA7543F00837A64 /* UIImage+Helper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Helper.m"; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1777,6 +1783,8 @@ 2901738A1E0A22940005F48B /* UIButton+countDown.m */, 298111101DFE674600F7EAFF /* UIImage+Fit.h */, 298111111DFE674600F7EAFF /* UIImage+Fit.m */, + 8FEF03F11EA7543F00837A64 /* UIImage+Helper.h */, + 8FEF03F21EA7543F00837A64 /* UIImage+Helper.m */, 2962D07F1CD1E6010058829D /* UIView+Frame.h */, 2962D0801CD1E6010058829D /* UIView+Frame.m */, 2916A7461D703A1700644C8C /* UIView+cornerRadius.h */, @@ -2311,6 +2319,7 @@ 29C30BD71DDC1E8C00CA3E29 /* ComprehensiveDiscussion */ = { isa = PBXGroup; children = ( + 8F7B45431EA61FB700E52092 /* ViewModels */, 2999B1301DE6CD760031F79E /* Cells */, 2999B12C1DE6CD4F0031F79E /* Controllers */, 298111171DFE9F2C00F7EAFF /* Models */, @@ -2885,6 +2894,15 @@ name = Pods; sourceTree = "<group>"; }; + 8F7B45431EA61FB700E52092 /* ViewModels */ = { + isa = PBXGroup; + children = ( + 8F7B45441EA61FED00E52092 /* ForumCommentListViewModel.h */, + 8F7B45451EA61FED00E52092 /* ForumCommentListViewModel.m */, + ); + path = ViewModels; + sourceTree = "<group>"; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -3095,6 +3113,7 @@ files = ( 293163FA1DCE3CBA0075129D /* LuckyDrawDetailsViewController.m in Sources */, 29CC51ED1E8A011E009FBB6A /* RebateDetailsViewController.m in Sources */, + 8F7B45461EA61FED00E52092 /* ForumCommentListViewModel.m in Sources */, 29045F321DCA192700E42A86 /* PromptHeaderTableViewCell.m in Sources */, 2940AE9B1DE7FE17001164B0 /* OnlineLearningDetailViewController.m in Sources */, 2986B9A31DE1D30700F4A1CF /* PromotionChooseNavigationController.m in Sources */, @@ -3377,6 +3396,7 @@ 29834EC01CDF5E4E001A484F /* ScreeningFirstCollectionViewCell.m in Sources */, 29834EC51CDF76C1001A484F /* UserViewController.m in Sources */, 29E2D3271DB88D8B00443170 /* CardOrderInformationReusableView.m in Sources */, + 8FEF03F31EA7543F00837A64 /* UIImage+Helper.m in Sources */, 2971E9841DF69F9A00256567 /* CountDownLabel.m in Sources */, 29CC51F81E8A032D009FBB6A /* LuckyDrawMainViewController.m in Sources */, 2962D06D1CD1A43A0058829D /* ClientViewController.m in Sources */, diff --git a/Lighting/LearningCenter.storyboard b/Lighting/LearningCenter.storyboard index a1737eedc9348ef580d3e579214852f06560c152..430242bbaaf5ff61ceb4f1c5cc816cbf968fe1de 100644 --- a/Lighting/LearningCenter.storyboard +++ b/Lighting/LearningCenter.storyboard @@ -1,10 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16E195" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES"> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES"> <device id="ipad9_7" orientation="landscape"> <adaptation id="fullscreen"/> </device> <dependencies> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/> <capability name="Constraints to layout margins" minToolsVersion="6.0"/> <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> @@ -359,7 +359,7 @@ <rect key="frame" x="0.0" y="28" width="1024" height="90"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ctQ-16-eCQ" id="DuY-Eq-G4z"> - <rect key="frame" x="0.0" y="0.0" width="830" height="89"/> + <rect key="frame" x="0.0" y="0.0" width="830" height="89.5"/> <autoresizingMask key="autoresizingMask"/> <subviews> <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="00登录-è°" translatesAutoresizingMaskIntoConstraints="NO" id="jVJ-Bu-xw9"> @@ -1065,7 +1065,7 @@ <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> <prototypes> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="AssessmentHeaderView" id="UfB-K3-NdF" customClass="AssessmentHeaderView"> - <rect key="frame" x="0.0" y="56" width="460" height="44"/> + <rect key="frame" x="0.0" y="55.5" width="460" height="44"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="UfB-K3-NdF" id="WGo-Wa-YTq"> <rect key="frame" x="0.0" y="0.0" width="460" height="44"/> @@ -1091,7 +1091,7 @@ </connections> </tableViewCell> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="AssessmentTableViewCell" rowHeight="52" id="gIe-bF-XsX" customClass="AssessmentTableViewCell"> - <rect key="frame" x="0.0" y="100" width="460" height="52"/> + <rect key="frame" x="0.0" y="99.5" width="460" height="52"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="gIe-bF-XsX" id="Va8-wn-DBM"> <rect key="frame" x="0.0" y="0.0" width="460" height="52"/> @@ -1137,7 +1137,7 @@ </connections> </tableViewCell> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="AssessmentShortAnswerTableViewCell" rowHeight="112" id="smV-qr-KgP" customClass="AssessmentShortAnswerTableViewCell"> - <rect key="frame" x="0.0" y="152" width="460" height="112"/> + <rect key="frame" x="0.0" y="151.5" width="460" height="112"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="smV-qr-KgP" id="A2f-ek-60T"> <rect key="frame" x="0.0" y="0.0" width="460" height="112"/> @@ -1373,7 +1373,7 @@ </collectionViewFlowLayout> <cells> <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="CalibrationDetailCollectionCell" id="dGo-4o-u9g" customClass="CalibrationDetailCollectionCell"> - <rect key="frame" x="0.0" y="10" width="93" height="41"/> + <rect key="frame" x="0.0" y="9.5" width="93" height="41"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center"> <rect key="frame" x="0.0" y="0.0" width="93" height="41"/> @@ -1453,7 +1453,7 @@ </collectionViewFlowLayout> <cells> <collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" reuseIdentifier="CalibrationCollectionViewCell" id="v20-Kz-8OX" customClass="CalibrationCollectionViewCell"> - <rect key="frame" x="0.0" y="5" width="50" height="50"/> + <rect key="frame" x="0.0" y="4.5" width="50" height="50"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center"> <rect key="frame" x="0.0" y="0.0" width="50" height="50"/> @@ -2157,7 +2157,7 @@ <rect key="frame" x="0.0" y="28" width="1024" height="100"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="Qnm-0r-wEL" id="VAA-bT-OlF"> - <rect key="frame" x="0.0" y="0.0" width="1024" height="99"/> + <rect key="frame" x="0.0" y="0.0" width="1024" height="99.5"/> <autoresizingMask key="autoresizingMask"/> <subviews> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="课时简介" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="agZ-rF-DnB"> @@ -2189,7 +2189,7 @@ <rect key="frame" x="0.0" y="128" width="1024" height="130"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="WzB-nZ-wsW" id="Zzv-Yi-ZxT"> - <rect key="frame" x="0.0" y="0.0" width="1024" height="129"/> + <rect key="frame" x="0.0" y="0.0" width="1024" height="129.5"/> <autoresizingMask key="autoresizingMask"/> <subviews> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="授课讲师" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="kxK-dX-OAf"> @@ -2246,7 +2246,7 @@ <rect key="frame" x="0.0" y="258" width="1024" height="100"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="oia-jO-L9n" id="AMF-ag-ZWN"> - <rect key="frame" x="0.0" y="0.0" width="1024" height="99"/> + <rect key="frame" x="0.0" y="0.0" width="1024" height="99.5"/> <autoresizingMask key="autoresizingMask"/> <subviews> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" text="针对人员" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="NfI-IM-h1i"> @@ -2747,7 +2747,7 @@ <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> <prototypes> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="AssessmentHeaderView" rowHeight="60" id="2M5-To-MLj" customClass="AssessmentHeaderView"> - <rect key="frame" x="0.0" y="56" width="1024" height="60"/> + <rect key="frame" x="0.0" y="55.5" width="1024" height="60"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="2M5-To-MLj" id="ypf-GL-4CP"> <rect key="frame" x="0.0" y="0.0" width="1024" height="60"/> @@ -2773,7 +2773,7 @@ </connections> </tableViewCell> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="AssessmentTableViewCell" rowHeight="50" id="BjI-a1-CRm" customClass="AssessmentTableViewCell"> - <rect key="frame" x="0.0" y="116" width="1024" height="50"/> + <rect key="frame" x="0.0" y="115.5" width="1024" height="50"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="BjI-a1-CRm" id="bq8-ly-DcD"> <rect key="frame" x="0.0" y="0.0" width="1024" height="50"/> @@ -3145,7 +3145,7 @@ <nil key="highlightedColor"/> </label> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8Th-tT-RVY"> - <rect key="frame" x="20" y="260" width="984" height="34"/> + <rect key="frame" x="20" y="245" width="984" height="49"/> <fontDescription key="fontDescription" type="system" pointSize="13"/> <nil key="textColor"/> <nil key="highlightedColor"/> @@ -3168,20 +3168,20 @@ <constraint firstAttribute="height" constant="1" id="fAA-nf-dma"/> </constraints> </view> - <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="b31-hr-5yT"> - <rect key="frame" x="20" y="88" width="400" height="164"/> + <view tag="1111" contentMode="scaleAspectFill" translatesAutoresizingMaskIntoConstraints="NO" id="b31-hr-5yT"> + <rect key="frame" x="20" y="73" width="400" height="164"/> <subviews> - <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Od7-sI-lw9"> + <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Od7-sI-lw9"> <rect key="frame" x="0.0" y="0.0" width="128" height="164"/> </imageView> - <imageView userInteractionEnabled="NO" tag="2" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="FpA-hd-kLS"> + <imageView clipsSubviews="YES" userInteractionEnabled="NO" tag="2" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="FpA-hd-kLS"> <rect key="frame" x="272" y="0.0" width="128" height="164"/> </imageView> - <imageView userInteractionEnabled="NO" tag="1" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="BTw-Cs-JhN"> + <imageView clipsSubviews="YES" userInteractionEnabled="NO" tag="1" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="BTw-Cs-JhN"> <rect key="frame" x="136" y="0.0" width="128" height="164"/> </imageView> </subviews> - <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> + <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/> <constraints> <constraint firstItem="BTw-Cs-JhN" firstAttribute="top" secondItem="b31-hr-5yT" secondAttribute="top" id="1oR-kk-w8t"/> <constraint firstItem="FpA-hd-kLS" firstAttribute="width" secondItem="Od7-sI-lw9" secondAttribute="width" id="4IH-iu-WUq"/> @@ -3201,21 +3201,20 @@ </view> </subviews> <constraints> - <constraint firstItem="pyu-Y7-w8M" firstAttribute="centerY" secondItem="iVT-bi-RKr" secondAttribute="centerY" constant="-109" id="0uV-p1-8pa"/> <constraint firstAttribute="bottom" secondItem="qn5-UZ-cM4" secondAttribute="bottom" id="4pS-CA-0MD"/> <constraint firstItem="8Th-tT-RVY" firstAttribute="leading" secondItem="iVT-bi-RKr" secondAttribute="leading" constant="20" id="52a-nf-bps"/> - <constraint firstItem="b31-hr-5yT" firstAttribute="top" secondItem="pyu-Y7-w8M" secondAttribute="bottom" constant="15" id="9Lt-gM-InY"/> + <constraint firstItem="b31-hr-5yT" firstAttribute="top" secondItem="pyu-Y7-w8M" secondAttribute="bottom" id="9Lt-gM-InY"/> <constraint firstItem="VAs-Wx-TQb" firstAttribute="leading" secondItem="iVT-bi-RKr" secondAttribute="leadingMargin" constant="20" id="A23-1U-p4J"/> <constraint firstAttribute="bottom" secondItem="8Th-tT-RVY" secondAttribute="bottom" constant="10" id="GHM-g1-aWA"/> <constraint firstItem="Nam-PB-SZa" firstAttribute="leading" secondItem="mfw-jx-1kt" secondAttribute="leading" id="LH1-AC-vh1"/> <constraint firstItem="mfw-jx-1kt" firstAttribute="top" secondItem="VAs-Wx-TQb" secondAttribute="top" id="LZO-yf-dpe"/> - <constraint firstItem="8Th-tT-RVY" firstAttribute="top" secondItem="iVT-bi-RKr" secondAttribute="top" constant="260" id="OyM-WB-gzg"/> <constraint firstItem="mfw-jx-1kt" firstAttribute="leading" secondItem="VAs-Wx-TQb" secondAttribute="trailing" constant="5" id="TQh-0R-Fcz"/> <constraint firstItem="qn5-UZ-cM4" firstAttribute="leading" secondItem="iVT-bi-RKr" secondAttribute="leading" id="Ttv-ma-62V"/> <constraint firstItem="8Th-tT-RVY" firstAttribute="top" secondItem="b31-hr-5yT" secondAttribute="bottom" constant="8" id="bak-X4-GJw"/> <constraint firstItem="b31-hr-5yT" firstAttribute="leading" secondItem="iVT-bi-RKr" secondAttribute="leading" constant="20" id="gUS-uZ-YEu"/> <constraint firstItem="G4o-Xy-Sd4" firstAttribute="centerY" secondItem="VAs-Wx-TQb" secondAttribute="centerY" id="iL8-0n-q90"/> <constraint firstItem="pyu-Y7-w8M" firstAttribute="centerX" secondItem="iVT-bi-RKr" secondAttribute="centerX" constant="-200" id="ifw-ag-xtC"/> + <constraint firstItem="pyu-Y7-w8M" firstAttribute="top" secondItem="iVT-bi-RKr" secondAttribute="top" constant="13" id="l4v-Ll-rbG"/> <constraint firstAttribute="trailing" secondItem="qn5-UZ-cM4" secondAttribute="trailing" id="ndM-Oc-58s"/> <constraint firstAttribute="trailing" secondItem="G4o-Xy-Sd4" secondAttribute="trailing" constant="30" id="saS-eK-h2C"/> <constraint firstItem="Nam-PB-SZa" firstAttribute="bottom" secondItem="VAs-Wx-TQb" secondAttribute="bottom" id="tv1-1o-GqD"/> diff --git a/Tools/Category/UIImage+Helper.h b/Tools/Category/UIImage+Helper.h new file mode 100644 index 0000000000000000000000000000000000000000..903b6a640992911bdbafea9f9e82901f3382ad0d --- /dev/null +++ b/Tools/Category/UIImage+Helper.h @@ -0,0 +1,67 @@ +// +// UIImage+Helper.h +// CXA +// +// Created by Xummer on 14-3-3. +// Copyright (c) 2014å¹´ Xummer. All rights reserved. +// + +#import <UIKit/UIKit.h> + +@interface UIImage (Helper) + ++ (UIImage *)getThumbnailImage:(UIImage *)image withMaxLen:(CGFloat)maxLen; +- (UIImage *)thumbnailWithMaxLen:(CGFloat)maxLen; + +- (UIImage *)imageWithTintColor:(UIColor *)tintColor; + +- (UIImage *)imageWithGradientTintColor:(UIColor *)tintColor; + +- (UIImage *)imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode; + +@end + +@interface UIImage (Color) ++ (UIImage *)imageWithColor:(UIColor *)color; ++ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size; ++ (UIImage *)imageWithColor:(UIColor *)color andRect:(CGRect)rect; +- (UIImage *)greyScaleImage; +/** + * 图片压缩到指定大å°ï¼ˆå…·ä½“看图片大å°ï¼Œè¿‡å¤§çš„å›¾ç‰‡æ— æ³•åŽ‹ç¼©åˆ°æŒ‡å®šå¤§å°ï¼‰ + * + * @param kb 压缩åŽå›¾ç‰‡å¤§å° + * + * @return + */ +- (NSData *)scaledToSpaceMaxSize:(NSInteger)kb; + +/** + * 压缩图片到指定高宽 + * + * @param newSize 新的图片尺寸 + * + * @return + */ +- (UIImage *)scaledToSize:(CGSize)newSize; + +/** + * 按比例压缩图片至指定宽度 + * + * @param newWidth 指定宽度 + * + * @return + */ +- (UIImage *)scaledToWidth:(NSInteger)newWidth; + + +/** + * 获å–图片缩略图 + * + * @param sourceImage 原始图片 + * @param size 生æˆå°ºå¯¸ + * + * @return 新的图片 + */ ++ (UIImage *)imageCompressForSize:(UIImage *)sourceImage targetSize:(CGSize)size; + +@end diff --git a/Tools/Category/UIImage+Helper.m b/Tools/Category/UIImage+Helper.m new file mode 100644 index 0000000000000000000000000000000000000000..c837438056c2919b2433f95c7e9d67b7c9c02831 --- /dev/null +++ b/Tools/Category/UIImage+Helper.m @@ -0,0 +1,270 @@ +// +// UIImage+Helper.m +// CXA +// +// Created by Xummer on 14-3-3. +// Copyright (c) 2014å¹´ Xummer. All rights reserved. +// + +#import "UIImage+Helper.h" + +@implementation UIImage (Helper) + +// if newImage's width or heigth < 1, image will be cliped ++ (UIImage *)getThumbnailImage:(UIImage *)image withMaxLen:(CGFloat)maxLen +{ + + CGFloat imageMaxLen, imageMinLen; + BOOL widthIsLarger = image.size.width > image.size.height; + if (widthIsLarger) { + imageMaxLen = image.size.width; + imageMinLen = image.size.height; + } + else { + imageMaxLen = image.size.height; + imageMinLen = image.size.width; + } + + if (imageMaxLen > maxLen) { + CGFloat scaleFloat = maxLen/imageMaxLen; + + CGFloat newImgMinL = imageMinLen * scaleFloat; + + CGSize size; + if (newImgMinL < 1) { + scaleFloat = 1/imageMinLen; + if (widthIsLarger) { + size = CGSizeMake(maxLen, image.size.height * scaleFloat); + } + else { + size = CGSizeMake(image.size.width * scaleFloat, maxLen); + } + + } + else { + size = CGSizeMake(image.size.width * scaleFloat, + image.size.height * scaleFloat); + } + + UIGraphicsBeginImageContext(size); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGAffineTransform transform = CGAffineTransformIdentity; + + transform = CGAffineTransformScale(transform, scaleFloat, scaleFloat); + CGContextConcatCTM(context, transform); + + // Draw the image into the transformed context and return the image + [image drawAtPoint:CGPointMake(0.0f, 0.0f)]; + UIImage *newimg = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + return newimg; + } + else{ + return image; + } +} + +- (UIImage *)thumbnailWithMaxLen:(CGFloat)maxLen { + return [[self class] getThumbnailImage:self withMaxLen:maxLen]; +} + +- (UIImage *)imageWithTintColor:(UIColor *)tintColor { + return [self imageWithTintColor:tintColor blendMode:kCGBlendModeDestinationIn]; +} + +- (UIImage *)imageWithGradientTintColor:(UIColor *)tintColor { + return [self imageWithTintColor:tintColor blendMode:kCGBlendModeOverlay]; +} + +- (UIImage *)imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode +{ + //We want to keep alpha, set opaque to NO; Use 0.0f for scale to use the scale factor of the device’s main screen. + UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f); + [tintColor setFill]; + CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height); + UIRectFill(bounds); + + //Draw the tinted image in context + [self drawInRect:bounds blendMode:blendMode alpha:1.0f]; + + if (blendMode != kCGBlendModeDestinationIn) { + [self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f]; + } + + UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + return tintedImage; +} + + +@end + +@implementation UIImage (Color) + +typedef enum { + ALPHA = 0, + BLUE = 1, + GREEN = 2, + RED = 3 +} PIXELS; + ++ (UIImage *)imageWithColor:(UIColor *)color { + CGRect rect = CGRectMake(0.0f,0.0f,1.0f,1.0f); + return [[self class] imageWithColor:color andRect:rect]; +} + ++ (UIImage *)imageWithColor:(UIColor *)color andRect:(CGRect)rect { + UIGraphicsBeginImageContext(rect.size); + CGContextRef context =UIGraphicsGetCurrentContext(); + CGContextSetFillColorWithColor(context,[color CGColor]); + CGContextFillRect(context, rect); + UIImage *image =UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return image; +} + ++ (UIImage *)imageWithColor:(UIColor *)color andSize:(CGSize)size { + return [[self class] imageWithColor:color andRect:(CGRect){ + .origin = CGPointZero, + .size = size + }]; +} + +- (UIImage *)greyScaleImage { + CGSize size = [self size]; + int width = size.width; + int height = size.height; + + // the pixels will be painted to this array + uint32_t *pixels = (uint32_t *) malloc(width * height * sizeof(uint32_t)); + + // clear the pixels so any transparency is preserved + memset(pixels, 0, width * height * sizeof(uint32_t)); + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + // create a context with RGBA pixels + CGContextRef context = CGBitmapContextCreate(pixels, width, height, 8, width * sizeof(uint32_t), colorSpace, + kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedLast); + + // paint the bitmap to our context which will fill in the pixels array + CGContextDrawImage(context, CGRectMake(0, 0, width, height), [self CGImage]); + + for(int y = 0; y < height; y++) { + for(int x = 0; x < width; x++) { + uint8_t *rgbaPixel = (uint8_t *) &pixels[y * width + x]; + + // convert to grayscale using recommended method: http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale + uint32_t gray = 0.3 * rgbaPixel[RED] + 0.59 * rgbaPixel[GREEN] + 0.11 * rgbaPixel[BLUE]; + + // set the pixels to gray + rgbaPixel[RED] = gray; + rgbaPixel[GREEN] = gray; + rgbaPixel[BLUE] = gray; + } + } + + // create a new CGImageRef from our context with the modified pixels + CGImageRef image = CGBitmapContextCreateImage(context); + + // we're done with the context, color space, and pixels + CGContextRelease(context); + CGColorSpaceRelease(colorSpace); + free(pixels); + + // make a new UIImage to return + UIImage *resultUIImage = [UIImage imageWithCGImage:image]; + + // we're done with image now too + CGImageRelease(image); + + return resultUIImage; +} + + +- (NSData *)scaledToSpaceMaxSize:(NSInteger)kb { + + //压缩到100kb以内 + CGFloat compression = 0.5f; + CGFloat maxCompression = 0.1f; + NSUInteger maxlength = kb * 1024; + NSData *imgData = UIImageJPEGRepresentation(self, compression); +// CLog(@"处ç†ä¹‹å‰çš„大å°--->%lukB",(unsigned long)imgData.length/1024); + while ([imgData length] > maxlength && compression > maxCompression) { + compression -= 0.1; + imgData = UIImageJPEGRepresentation(self, compression); + + } +// CLog(@"处ç†ä¹‹åŽçš„大å°--->%lukB",(unsigned long)imgData.length/1024); + + + return imgData; + +} + +- (UIImage *)scaledToSize:(CGSize)newSize { + UIGraphicsBeginImageContextWithOptions(newSize, YES, 0); + [self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; + UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return scaledImage; +} + +- (UIImage *)scaledToWidth:(NSInteger)newWidth { + + CGSize newSize = CGSizeMake(newWidth, newWidth / self.size.width * self.size.height); + UIGraphicsBeginImageContextWithOptions(newSize, YES, 0); + [self drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)]; + UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + return scaledImage; +} + +#pragma mark - 获å–缩略图 ++ (UIImage *)imageCompressForSize:(UIImage *)sourceImage targetSize:(CGSize)size +{ + UIImage *newImage = nil; + CGSize imageSize = sourceImage.size; + CGFloat width = imageSize.width; + CGFloat height = imageSize.height; + CGFloat targetWidth = size.width; + CGFloat targetHeight = size.height; + CGFloat scaleFactor = 0.0; + CGFloat scaledWidth = targetWidth; + CGFloat scaledHeight = targetHeight; + CGPoint thumbnailPoint = CGPointMake(0.0, 0.0); + if(CGSizeEqualToSize(imageSize, size) == NO){ + CGFloat widthFactor = targetWidth / width; + CGFloat heightFactor = targetHeight / height; + if(widthFactor > heightFactor){ + scaleFactor = widthFactor; + } + else{ + scaleFactor = heightFactor; + } + scaledWidth = width * scaleFactor; + scaledHeight = height * scaleFactor; + if(widthFactor > heightFactor){ + thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5; + }else if(widthFactor < heightFactor){ + thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5; + } + } + UIGraphicsBeginImageContextWithOptions(size, NO, 3.0); + CGRect thumbnailRect = CGRectZero; + thumbnailRect.origin = thumbnailPoint; + thumbnailRect.size.width = scaledWidth; + thumbnailRect.size.height = scaledHeight; + [sourceImage drawInRect:thumbnailRect]; + newImage = UIGraphicsGetImageFromCurrentImageContext(); + if(newImage == nil){ + NSLog(@"scale image fail"); + } + UIGraphicsEndImageContext(); + return newImage; + +} + +@end