ios 图片显示模式 scaleAspectFit 后的处理

来源:互联网 发布:js 对象排序 编辑:程序博客网 时间:2024/05/17 14:17
scaleAspectFit 模式下  有空白   以下为处理 比例缩放 。 AVMakeRect 为 

AVFoundation框架 

 //得到图片的高

    func getImageHeight(imagev:UIImageView) ->CGSize {

 //图片image 在imageview 的位置

        let iamgeAspectRect =AVMakeRect(aspectRatio: (imagev.image?.size)!, insideRect: imagev.bounds);

         //图片比例

        let scale = iamgeAspectRect.size.height/iamgeAspectRect.size.width;

         //重置

        let hight = (imagev.frame.size.width - iamgeAspectRect.size.width)*scale+iamgeAspectRect.size.height;


        returnCGSize(width: imagev.frame.size.width, height: hight)

    }