xcode 使 UIScrollview 滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4689506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
make UIScrollview scroll
提问by Csabi
I have porblem that my UIScrollView
does not scroll I don't think that is a problem with iphone emulator. Here is my way to construct UIScrollView
:
我有UIScrollView
不滚动的问题,我认为这不是 iphone 模拟器的问题。这是我的构建方式UIScrollView
:
[scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES; // default is NO, we want to restrict drawing within our scrollview
scrollView.scrollEnabled = YES;
and I add UILabel
to it, to which later I add some info from xml.
然后我添加UILabel
到它,稍后我从 xml 添加一些信息。
labeL = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 1000)];
labeL.numberOfLines = 0;
labeL.text =@"";
[scrollView addSubview:labeL];
this is how I add value to UILabel
:
这就是我增加价值的方式UILabel
:
vypisObratString = [[NSMutableString alloc] initWithString:labeL.text];
if (turnOver) {
turnOver = NO;
[vypisObratString appendString:@"----------------"];
[vypisObratString appendString:@"\n"];
labeL.text = vypisObratString;
}
But when I compile the program it writes the corect values but the last line is like this:
但是当我编译程序时,它会写入正确的值,但最后一行是这样的:
12.1.2010...
and it does not scroll. Why? What I missing?
它不会滚动。为什么?我错过了什么?
回答by James Lelyveld
I think your issue is with setting the size of the scroll view which needs to be larger than the size of the iphone (i.e. it needs to know that there is some area outside the phone display to scroll to). Something along these lines:
我认为您的问题是设置滚动视图的大小,该大小需要大于 iphone 的大小(即它需要知道手机显示屏之外有一些区域可以滚动到)。沿着这些路线的东西:
UIScrollView *tempScrollView=(UIScrollView *)self.view;
tempScrollView.contentSize=CGSizeMake(800,800);
That should be all you need to make it scroll.
这应该是您让它滚动所需的全部内容。
Cheers
干杯
James
詹姆士