ps:因为这段时间做聊天功能,基本已经稳定,剩下就是优化小细节,今天发现聊天发送的图片和微信图片差别略大,网上搜了一下没有搜到相关代码,都是按尺寸相等缩小或剪裁等,自己记录一下方便以后用上,
代码贴上:
+ (CGSize)neededSizeForPhoto:(CGSize*)bubbleSize {
//bubbleSize 原尺寸
CGFloat maxWidth = IPHONE_WIDTH * 0.46; //限制最大宽度或高度
CGFloat imageViewW = bubbleSize.width/2;
CGFloat imageViewH = bubbleSize.height/2;
CGFloat factor = 1.0f;
if(imageViewW > imageViewH){
if(imageViewW > maxWidth){
factor = maxWidth/imageViewW;
imageViewW = imageViewW*factor;
imageViewH = imageViewH*factor;
}else{
if(imageViewH > maxWidth){
factor = maxWidth/imageViewH;
imageViewW = MAX(imageViewW*factor,46.0); //限制宽度不能超过46.0
imageViewH = imageViewH*factor;
}
}
bubbleSize = CGSizeMake(imageViewW, imageViewH);
return bubbleSize;
}