UIScrollView 不会滚动
我已尝试以下操作:
contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 600, 400)];
[contentScrollView setContentSize:CGSizeMake(600, 400)];
[contentScrollView addSubview:twitterSigninViewController.view];
[contentScrollView setScrollEnabled:YES];
但是,这不会滚动。这是为什么呢?
I have tried the following:
contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 600, 400)];
[contentScrollView setContentSize:CGSizeMake(600, 400)];
[contentScrollView addSubview:twitterSigninViewController.view];
[contentScrollView setScrollEnabled:YES];
However, this doesn't scroll. Why is this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它不会滚动,因为没有什么可滚动的。您告诉它您的内容大小与滚动视图本身的大小完全相同,因此它已经显示了所有内容。如果您希望它在尝试滚动时始终弹起,您可以设置
alwaysBounceHorizontal
或alwaysBounceVertical
属性,仅此而已。It doesn't scroll because there's nothing to scroll. You told it your content size was exactly the same size as the scrollview itself, so it's already displaying everything. You can set the
alwaysBounceHorizontal
oralwaysBounceVertical
properties if you want it to always bounce when trying to scroll, but that's about it.问题是框架大小(实际视图有多大)与您的内容大小(您的内容有多大)相同。因此,如果您使框架的高度小于 contentSize 的高度,它将滚动。
The issue is the frame size (how large the actual view is) is the same as your content size (how large your content is). So if you make your frame's height less than your contentSize's height it will scroll.
对您问题的简单回答将
setContentSize:
行更改为:Simple answer to your question change
setContentSize:
line to: