2013-03-27 41 views
1

嗨,在我的iPad應用程序中,我有一個圖像視圖和數據的列表意味着我從服務器獲得的圖像。我可以在沒有任何問題的情況下在尊重圖像瀏覽中加載所有圖像。但是在這裏,我觀察到一個異常現象,很少有圖像在圖像瀏覽中的分辨率很好,很少有圖像看起來在圖像瀏覽中被拉伸。根據我的知識,我覺得這是發生的,因爲圖像大小超過了imageview的大小,所以發生了。但是,我從服務器獲得的數據,所以我無法控制大小。所以任何人都可以展示任何解決方案如何解決此問題。意思是我不想在圖像瀏覽中拉伸圖像。請幫幫我。如何在iOS中保留基於圖片大小的imageview大小?

+1

yourImageView.contentMode = UIViewContentModeScaleAspectFit;試試這個,讓我知道 – Spynet 2013-03-27 08:53:24

+0

嗨Spynet非常感謝。 – Naresh 2013-03-27 11:19:39

回答

0

試試這個我希望這會有所幫助

yourImageView.contentMode=UIViewContentModeScaleAspectFit; 
1

如SpyNet中提到,嘗試UIViewContentModeScaleAspectFit

或添加這個方法來調整圖像大小,你想

- (UIImage *)scaleAndRotateImage:(UIImage *)imagerotate { 

     CGImageRef imgRef = imagerotate.CGImage; 

    CGFloat width = CGImageGetWidth(imgRef); 
    CGFloat height = CGImageGetHeight(imgRef); 

    CGAffineTransform transform = CGAffineTransformIdentity; 
    CGRect bounds = CGRectMake(0, 0, width, height); 

    CGFloat boundHeight; 

    boundHeight = bounds.size.height; 
    bounds.size.height = bounds.size.width; 
    bounds.size.width = boundHeight; 
    transform = CGAffineTransformMakeScale(-1.0, 1.0); 
    transform = CGAffineTransformRotate(transform, M_PI/2.0); //use angle/360 *MPI 

    UIGraphicsBeginImageContext(bounds.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextConcatCTM(context, transform); 
    CGContextDrawImage(context, CGRectMake(0, 0, width, height), imgRef); 
    UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
// UIImageWriteToSavedPhotosAlbum(imageCopy, nil, nil, nil); 
return imageCopy; 

} 

並添加此調用的方法

UIImage *imgResized=[self scaleAndRotateImage:imageReceived]; 
+0

非常感謝猩紅色的巫婆。 – Naresh 2013-03-27 11:19:16

+1

歡迎@gadamsetty。它有用嗎? – ScarletWitch 2013-03-27 12:44:23