【发布时间】:2012-11-12 19:31:47
【问题描述】:
我有一个 UIViewController 和一个 UIScrollView。由于我必须向视图控制器添加多个视图,而滚动视图只是其中之一,因此我尝试将控制器的视图设置为虚拟 UIView 并将滚动设置为子视图,如下所示:
[self setView:[[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]];
[[self view] setUserInteractionEnabled:NO];
// TDHexMapScrollView inherits from UIViewController
[self setHexMapScrollView:[[TDHexMapScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]];
[[self view] addSubview:[self hexMapScrollView]];
这样滚动不起作用。将其添加为主视图使滚动和平移正常工作:
[self setHexMapScrollView:[[TDHexMapScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]];
[self setView:[self hexMapScrollView]];
有什么帮助吗?谢谢
【问题讨论】:
-
检查两者是否都有 userInteractionEnabled=YES
-
你试过设置
contentInset -
scrollView 是否包含所有其他视图?或者你只是想滚动某个子集?我已经做过很多次了,但我对你可能缺少的第一个猜测是
[TDHexMapScrollView setContentSize:size of the views to be scrolled];
标签: ios uiview uiscrollview