<h3>ps:因为这段时间做聊天功能,基本已经稳定,剩下就是优化小细节,今天发现聊天发送的图片和微信图片差别略大,网上搜了一下没有搜到相关代码,都是按尺寸相等缩小或剪裁等,自己记录一下方便以后用上,</h3>
<h6>代码贴上:</h6>
+ (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;
}
<h6>效果:</h6>
1616684-15e3eec185fd9065.png
网友评论