2012-07-01 89 views
0

我有一個視圖,其中包含一些事件的細節,其中包括imageview,一些標籤等。 我將視圖中的小型子視圖描述爲可滾動的視圖,如下所示。在iPhone視圖中滾動頁面

CGRect descriptionTextViewRect = CGRectMake(15, 185, 280, 85); 
descriptionText = [[UITextView alloc] initWithFrame:descriptionTextViewRect]; 
descriptionText.textAlignment = UITextAlignmentLeft; 
descriptionText.text =des; 
descriptionText.editable = NO; 
descriptionText.layer.cornerRadius = 5.0; 
descriptionText.clipsToBounds = YES; 
descriptionText.userInteractionEnabled = YES; 
descriptionText.font = [UIFont systemFontOfSize:15]; 
[scrollView addSubview: descriptionText]; 

我跟着這個link,但我得到滾動兩個文本視圖和滾動視圖

我也跟着這樣

float sizeOfContent = 0; 
int i ; 

for (i=0; i<[scrollView.subviews count]; i++) { 
    sizeOfContent += descriptionText.frame.size.height; 
} 

scrollView.contentSize = CGSizeMake(descriptionText.frame.size.width, sizeOfContent) 

我需要顯示的描述的全部內容和使整個詳細信息頁面可滾動。

我做得對嗎?或者我錯過了某些東西?

我該怎麼做?

謝謝。

回答

0

您正在多次添加同一項目的高度。

此:

for (i=0; i<[scrollView.subviews count]; i++) { 
    sizeOfContent += descriptionText.frame.size.height; 
} 

應該是這樣的:

for (UIView *view in scrollView.subviews) { 
    sizeOfContent += view.frame.size.height; 
} 

,以便正常添加的所有項目的高度,以sizeOfContent

+0

確切的,但我需要設置說明文本的大小並使詳細信息頁面可滾動。我現在只能滾動描述文字。你能爲此提供建議嗎? – user1268938

0

您每次都在同一位置添加子視圖。例如:如果您要添加5個子視圖,它應該如下所示:

for(int i=0; i<5; i++) 
{ 
CGRect descriptionTextViewRect = CGRectMake(15, i*185, 280, 85); 
descriptionText = [[UITextView alloc] initWithFrame:descriptionTextViewRect]; 
descriptionText.textAlignment = UITextAlignmentLeft; 
descriptionText.text =des; 
descriptionText.editable = NO; 
descriptionText.layer.cornerRadius = 5.0; 
descriptionText.clipsToBounds = YES; 
descriptionText.userInteractionEnabled = YES; 
descriptionText.font = [UIFont systemFontOfSize:15]; 
[scrollView addSubview: descriptionText]; 
} 
相關問題