0

我正在尝试使用 mainScrollView 实现视图。在 mainScrollView 里面我有 10 个 UIView,每个都有 subScrollView。现在,我想在每个 subScrollView 中添加许多(大约 150 到 200 个)视图(imageview、label、textview、uiview、webview 等)。

像这样的东西:

二战时间线爵士乐历史

我尝试了以下方法:
方法1:

延迟加载每个 subScrollView 以添加视图。

代码:

-(void)loadInnerScrollViewLazily:(int)tag pageNo:(int)pageNo{

/// this array will contain all the views for subScrollView

NSMutableArray *array=[NSMutableArray array];
array=[self.tlScrollContentArray objectAtIndex:tag];  

if (pageNo < 0)
    return;
if (pageNo >= [array count])
    return;

UIView *controller = [array objectAtIndex:pageNo];
CGRect frame = [[array objectAtIndex:0] frame];
frame.origin.x = 350;
frame.origin.y = 0;
controller.frame = frame;

for (UIView* view in [mainScrollView subviews]) {
    for (UIScrollView* scroll in [view subviews]) {
        if ([scroll isKindOfClass:[UIScrollView class]]) {
              if (scroll.tag == tag+11) {

                [scroll addSubview:controller];   /// adds view in particular subScrollView

            }
        }
    }
}

}

此方法在 scrollViewDidScroll 方法中调用,该方法检查特定的 scrollView 并删除屏幕外的视图,然后根据条件添加视图。

随着滚动速度的增加,此代码正在减慢应用程序的速度。

方法二:

参考教程:

在 mainScrollView 中添加三个 UIView(每个都有 subScrollView)。根据条件更新 subScrollView 的内容。

但是这个解决方案也减慢了我的应用程序,因为它每次出现时都会更新 subScrollView。

是否有任何库或代码可用于管理它。

任何帮助将不胜感激。

提前致谢!

4

1 回答 1

0

I think your code has many, many errors, and you would need to post your complete source to be helped. It's unclear if you are ever removing images from your scrollview. If not, that is your problem.

Look at Apple's sample PhotoScroller code: http://developer.apple.com/library/ios/#samplecode/PhotoScroller/Introduction/Intro.html

This dequeues and manages the ImageViews on the scrollview... I implemented something similar based on this.

于 2012-08-14T13:12:00.590 回答