2013-04-30 166 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

相关问题