2011-12-28 205 views
0

我有一個滾動視圖,我可以根據滾動視圖中的內容動態調整其contentSize。問題在於,在完成所有調整之後,它不會滾動到頂部。我嘗試將contentOffset設置爲0,0,但這並不奏效。UIScrollView不滾動到頂部

我正在使用故事板..任何想法這可能是什麼?

這裏是一些代碼

[scrollView setScrollEnabled:YES]; 
[scrollView setContentSize:CGSizeMake(320, 700)]; 
[scrollView setBackgroundColor:[UIColor colorWithRed:0.892 green:0.893 blue:0.892 alpha:1.0]]; 

移動標籤

// Move Description Label/Image 
self.descriptionImageView.frame = CGRectMake(20, self.importantInfo.frame.origin.y + self.importantInfo.frame.size.height + 20, self.descriptionImageView.frame.size.width, descriptionImageView.frame.size.height); 
self.descriptionLabel.frame = CGRectMake(self.descriptionImageView.frame.origin.x + self.descriptionImageView.frame.size.height + 20, self.importantInfo.frame.origin.y + self.importantInfo.frame.size.height + 20, self.descriptionLabel.frame.size.width, self.descriptionLabel.frame.size.height); 

// Adjust scroll size so it does not scroll out the content 
[scrollView setContentSize:CGSizeMake(scrollView.contentSize.width, description.frame.origin.y + description.frame.size.height + 20)]; 

enter image description here

+1

你可以打印滾動視圖的框架進行調試嗎? – 2011-12-28 12:07:09

+0

它是:{{0,0},{320,460}} – Chris 2011-12-28 12:20:58

+1

通過刪除scrollview並添加一個新的完全相同的數字...它保持參考的高度爲460 .. 。謝謝你的提示!您應該創建一個答案,以便將其標記爲已回答。 – Chris 2011-12-28 12:55:20

回答

0

你應該確保在UIScrollView的定位和大小正確。

嘗試將它定位在x:0和y:44處。並將其高度設置爲436像素。

讓我知道它是否工作:)

+0

滾動視圖將不會使用全視圖。由於視圖的大小是320/367 – Chris 2011-12-28 12:32:10