2013-04-30 163 views
1

我是IOS編程中的新手,我有一個tableview,當我選擇表中的一個項目時會拉起一個細節視圖。詳細視圖有標題,圖片,底部有一個textview。所有這些項目都在滾動視圖內。我希望整個頁面不僅滾動文本。問題是textview是可滾動的,所以我有兩個滾動條,一個用於視圖的主滾動條,另一個用於文本,我需要的是將兩個滾動條組合起來,這意味着當我滾動時需要滾動條視圖中,文本立即滾動。textview裏面的滾動視圖ios

這是一個關於視圖的屏幕截圖:

enter image description here

和滾動被禁用:

enter image description here

這是更新所述高度約束

enter image description here

這是滾動視圖屬性

enter image description here

代碼的截圖:

 NSString *text =[[jsonResults objectAtIndex:0] objectForKey:@"content"]; 

    CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize:14] 
         constrainedToSize:CGSizeMake(300, 5000) lineBreakMode:NSLineBreakByCharWrapping]; 

    [self.detailTextView setFrame:CGRectMake(self.detailTextView.frame.origin.x,self.detailTextView.frame.origin.y,textSize.width,textSize.height)]; 

    [self.detailTextView setText:text]; 
scroll.ContentSize=CGSizeMake(320,1000); 

謝謝你了很多,

回答

0

要將

我想整個頁面滾動不只是文字

1)It will happen only if the contentSize of your view is larger than the screen size 

e.g(如果屏幕是420,你的內容是近600東西,然後滾動視圖會滾動),我想,當我滾動視圖,文字立即用它滾動

2) If the content of the text inside your UITextView is more than the height of the UITextView then automatically your textView will scroll 
2

嘗試這樣,

在你的情況做一本集動態基於文本TextView的框架和禁用的TextView的滾動。而添加的TextView到滾動型。

enter image description here

取消滾動啓用TextView的的。

+0

@CarinaM:你有沒有這樣試過? – Balu 2013-04-30 10:09:16

+0

是的,我關掉了文字視圖的滾動,但文字仍然不適合內容。 – CarinaM 2013-04-30 10:50:17

+0

意味着在textview中遺漏了一些文本? – Balu 2013-04-30 10:51:44

1

enter image description here

在自的UITextView的高度你的情況是小於文字的高度,因此,它顯示滾動。

UITextView *textView=[[UITextView alloc] init]; 

NSString *text = @"Your Text Here"; 

CGSize textSize = [text sizeWithFont:[UIFont fontWithName:@"YourFontName" size:YourFontSize] 
        constrainedToSize:CGSizeMake(MaximumWidthForTextView, MaximumHeightForTextView) lineBreakMode:NSLineBreakByWordWrapping]; 

[textView setFrame:CGRectMake(textView.frame.origin.x,textView.frame.origin.y,textSize.width,textSize.height)]; 

[textView setText:text]; 
[self.scrollView addSubview:textView]; 

float scrollViewContentHeight = textView.frame.origin.y+textView.frame.size.height+20; 
[self.scrollView setContentSize:CGSizeMake(320,scrollViewContentHeight)]; 

通過這樣做你的textview將不會顯示滾動了。現在第二個問題是關於在UIScrollView中滾動。爲了在UIScrollView中引入滾動,你需要設置滾動視圖的內容大小。 例如: -

[scrollView setContentSize:CGSizeMake:(320 , 600)]; 

在以下例子中其中i已設置的內容的大小爲320600,滾動視圖將顯示自滾動視圖的內容高度滾動的屬性比畫面高度(屏幕尺寸更大的iphone 4s的情況 - (320,480));

+0

嗨,我用了你說的,但是窗臺不工作,我應該在故事板屬性中做其他事情嗎? – CarinaM 2013-04-30 11:54:07

+0

請你能檢查上面的截圖嗎? 非常感謝你 – CarinaM 2013-04-30 11:56:40

+0

你在哪裏設置UIScrollView的contentSize? – 2013-04-30 11:56:49

相關問題