2012-07-24 88 views
0

我在ScrollView中有一個ImageView,並在某個時間調整了ScrollView的大小。問題是,ImageView調整爲與ScrollView相同的大小,但我希望它保持原始圖像大小。Scrollview中的圖像大小調整

我在做什麼,這是:

scrollView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); // fullscreen scrollview 
[scrollView setContentMode:UIViewContentModeTopLeft]; //i want the content to be on the top left, thats correct right? 
[scrollView setContentSize:CGSizeMake(imageInScrollView.frame.size.width, imageInScrollView.frame.size.height)]; // now im setting the size of the content, which is like 200x200 but it shows in fullscreen 

請閱讀我旁邊的代碼中的註釋,謝謝!

回答

0

您需要更改autoresizingMaskUIView

autoresizingMask
一個整數位掩碼,決定接收機如何調整自身大小 當它的父的邊界變化。

你可以做到這一點是這樣的:

[myImageView setAutoresizingMask:UIViewAutoresizingNone]; 
+0

加入這一行我的代碼,但它什麼也沒做 – oybcs 2012-07-24 09:19:35

0

的的UIScrollViewcontentSize不影響拉絲,它只是用於滾動目的(即定義了一個矩形內,用戶可以滾動)。

請提供有關imageInScrollView,它是包含在UIImageView更多信息特別檢查其frame屬性是正確的,你想要什麼,並檢查其autoresizingMask:你可能要像

imageView.autoresizingMask = UIViewAutoresizingNone; 

最後,您應該做的:

[scrollView setContentSize:imageView.frame.size]; 

,因爲這是更簡單的

+0

嗨,我檢查了兩者的框架。 imageInScrollView(實際上是一個ImageView)和滾動視圖350.000000,335.000000 // imageview - 540.000000,576.000000 //滾動視圖..並且它沒有用於放置autoresizingnone – oybcs 2012-07-24 09:17:58

+0

什麼是imageView.image.size? – Olotiar 2012-07-24 09:40:40

+0

對不起,image.size是350x335,而imageView的框架是:540.000000,516.857178 – oybcs 2012-07-24 09:47:52