简体   繁体   English

UIScrollView作为另一个UIScrollView的子视图

[英]UIScrollView as subview of another UIScrollView

Is it possible to have a small vertical scrollview as subview of another bigger vertical scrollview? 是否可以有一个小的垂直滚动视图作为另一个更大的垂直滚动视图的子视图?

I made a small prototype. 我做了一个小原型。 When the scrollviews are not hierarchical (if I put them side by side for example), both scroll correctly. 当滚动视图不是分层视图时(例如,如果我将它们并排放置),则两者都可以正确滚动。 But if I put one as a subview of the other, then only the sub scrollview scrolls when I pan it and the top scrollview seems to be locked when I pan it. 但是,如果将一个作为另一个视图的子视图,则在平移它时只有子滚动视图滚动,而在平移它时顶部的滚动视图似乎被锁定。

I envision that if the user pans the embedded scrollview (subSV in diagram below), then only the embedded scrollview would scroll. 我设想,如果用户平移嵌入式滚动视图(下图中的subSV),则只有嵌入式滚动视图会滚动。 Similarly, if the user pans the top scrollview, then only the top scrollview would move and the embedded scrollview may be scrolled out of the visible content. 类似地,如果用户平移顶部滚动视图,则仅顶部滚动视图将移动,并且嵌入式滚动视图可以从可见内容中滚动出来。

Do you know of any sample code that does this? 您知道执行此操作的任何示例代码吗?

UIScrollView作为另一个UIScrollView的内容

Apparently is fully supported from 3.0 onwards, and should be automatic (see http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/UIScrollView_pg/NestedScrollViews/NestedScrollViews.html ). 显然从3.0开始完全受支持,并且应该是自动的(请参阅http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/UIScrollView_pg/NestedScrollViews/NestedScrollViews.html )。 They provide sample code as well, which might contain an example of nested UIScrollView s. 它们还提供了示例代码,其中可能包含嵌套的UIScrollView的示例。

I was able to make it work with programmatically but not using StoryBoard. 我能够使其以编程方式工作,但无法使用StoryBoard。 Here is the trivial piece of code: 这是一些琐碎的代码:

UIScrollView *topSV = [[UIScrollView alloc] initWithFrame:CGRectMake(100.0f, 100.0f, 600.0f, 600.0f)];
topSV.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
topSV.contentSize = CGSizeMake(2000.0f, 2000.0f);

UIScrollView *subSV = [[UIScrollView alloc] initWithFrame:CGRectMake(10.0f, 10.0f, 200.0f, 200.0f)];
subSV.backgroundColor = [UIColor whiteColor];
subSV.contentSize = CGSizeMake(2000.0f, 2000.0f);

[topSV addSubview:subSV];

[self.window addSubview:topSV];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM