知道UIImageView中图像的真实边界

AP.*_*AP. 3 iphone uiimageview uiimage

我正在使用UIImageView加载带有aspectfit的图像.因此,图像确实使用整个UIImageView表面.如何知道UIImageView中图像的边界是什么?

提前致谢

Cos*_*que 6

CGFloat aspectRatioX = imageView.bounds.size.width/imageView.image.size.width;
CGFloat aspectRatioY = imageView.bounds.size.height/imageView.image.size.height;
if ( aspectRatioX < aspectRatioY )
    imageRect = CGRectMake(0, (imageView.bounds.size.height - aspectRatioX*imageView.image.size.height)*0.5f, imageView.bounds.size.width, aspectRatioX*imageView.image.size.height);
else
    imageRect = CGRectMake((imageView.bounds.size.width - aspectRatioY*imageView.image.size.width)*0.5f, 0, aspectRatioY*imageView.image.size.width, imageView.bounds.size.height);
Run Code Online (Sandbox Code Playgroud)