当前位置:编程学习 > wap >>

一个从UIImageView中获得Image位置的函数

[cpp]  
  
[cpp]  
(CGRect)getFrameSizeForImage:(UIImage *)image inImageView:(UIImageView *)imageView {  
     
   float hfactor = image.size.width / imageView.frame.size.width;  
   float vfactor = image.size.height / imageView.frame.size.height;  
     
   float factor = fmax(hfactor, vfactor);  
     
   // Divide the size by the greater of the vertical or horizontal shrinkage factor  
   float newWidth = image.size.width / factor;  
   float newHeight = image.size.height / factor;  
     
   // Then figure out if you need to offset it to center vertically or horizontally  
   float leftOffset = (imageView.frame.size.width - newWidth) / 2;  
   float topOffset = (imageView.frame.size.height - newHeight) / 2;  
     
   return CGRectMake(leftOffset, topOffset, newWidth, newHeight);  
 
废话不多说贴代码。再stackOverflow中找到的马克下!
补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,