2013-12-22 38 views
-1

我在製作應用程序,需要在模態屏幕中顯示圖像。在我的xib中,我製作了UIImage視圖的全屏大小。當圖像顯示時,它在屏幕中居中。這在iPhone5上正常工作。但是,當我回到測試4時,無論我如何使圖像居中在屏幕上,導致圖像顯示在頁面中間一半,因爲圖像視圖太大,我似乎無法縮小圖像視圖爲屏幕。滾動視圖似乎調整正確,我不知道爲什麼圖像wiew不會。症狀的下面enter image description here 相關代碼的4S無法在iPhone4和iPhone5之間調整UIImageView的大小

屏幕截圖:

[self.scrollView setZoomScale:self.scrollView.minimumZoomScale animated:YES]; 
[self.myView setTranslatesAutoresizingMaskIntoConstraints:YES]; 
[self.scrollView setTranslatesAutoresizingMaskIntoConstraints:YES]; 
[self.imageView setTranslatesAutoresizingMaskIntoConstraints:YES]; 

NSURL *url = [NSURL URLWithString:self.myImage]; 
NSData *data = [NSData dataWithContentsOfURL:url]; 
img = [[UIImage alloc] initWithData:data]; 

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

[self.scrollView setZoomScale:self.scrollView.minimumZoomScale animated:YES]; 
CGSize imageSize = [self currentScreenBoundsDependOnOrientation]; 

self.imageView.frame = self.myView.bounds ; 
self.scrollView.frame = self.myView.bounds; 

imageWithAlignmentRectInsets:UIEdgeInsetsMake(0, 0, 20, 20); 
+0

您是否嘗試過調整圖像大小。我想這會修復 –

+0

在iPhone 4和iPhone 5上產生的幀值是什麼? – Sulthan

+0

就是這樣。主視圖框太大,所以我只是根據屏幕大小來修復它。謝謝@Sulthan – Dnaso

回答

0

有很多事情可能出錯。

  1. 確保autoresizesSubviews設置爲NO在滾動視圖或autoresizingMaskimageView設置爲none(你不想imageView.framescrollView.frame的改變而改變)。

  2. 您確定要圖像居中嗎?如果圖像居中且圖像視圖比它小(這可能是iphone 4上的情況),那麼顯然圖像的一部分將被隱藏。你確定你不想contentMode被設置爲UIViewContentModeScaleAspectFit?或者甚至更好,你確定你不想讓imageView與圖像具有相同的尺寸,並使用scrollView來查看圖像?

+0

蘇爾坦,是的,我確實設置了比例尺以適合..但是由於imageview在4上更大並且不會調整到460,所以我的圖像是屏幕的一半。我的意思是我希望圖像在屏幕上居中,而不是隻是視圖。另外,如果我這樣做比圖像真的大,我必須手動調整圖像的大小嗎? – Dnaso

+0

結果是一樣的.. – Dnaso