1

帮我。addSubview 不起作用。我想在 scrollView 上添加“ContentView”。但是“ContentView”没有出现在屏幕上。“内容视图”是 UIView。

当我从 [self.view addSubview:scrollView] 更改为 self.view=scrollView 时,addSubview 不起作用。

请教我如何在这个屏幕上添加 UIView !

- (void)viewDidLoad {
[super viewDidLoad];

scrollViewMode = ScrollViewModeNotInitialized;
mode = 1;
imageViewArray = [[NSMutableArray alloc] init]; 
mainStatic = [[MainStatics alloc] init];    
[mainStatic setSetting];
NSString* path = [[NSBundle mainBundle] pathForResource:@"Files" ofType:@"plist"];      
NSArray* dataFiles = [NSArray arrayWithContentsOfFile:path];    
kNumImages = [dataFiles count]; 

CGRect frame = [UIScreen mainScreen].applicationFrame;
scrollView = [[touchClass alloc] initWithFrame:frame];
scrollView.delegate = self;
scrollView.maximumZoomScale = 5.0f;
scrollView.minimumZoomScale = 1.0f;
[scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setDelegate:self];
scrollView.delaysContentTouches=NO;
scrollView.userInteractionEnabled = YES;
[scrollView setCanCancelContentTouches:NO];

NSUInteger i;                                                   
for (i=0;i<[dataFiles count];i++)
{
    UIImage* image = [UIImage imageNamed:[dataFiles objectAtIndex:i]];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.contentMode = UIViewContentModeScaleAspectFit;                
    imageView.userInteractionEnabled = NO;                                  
    CGRect rect = imageView.frame;                                          
    rect.size.height = 480;                                 
    rect.size.width = 320;                                      
    imageView.frame = rect;                                                 
    imageView.tag = i+1;                                                                       
            [imageViewArray addObject:imageView];
}

self.view = scrollView;

[self setPagingMode];
UIView* contentView;                                            
CGRect scRect = CGRectMake(0, 436, 320, 44);                    
contentView = [[UIView alloc] initWithFrame:scRect];
[contentView addSubview:toolView];                              
[self addSubview:contentView];                              

}

4

2 回答 2

1

我在以下函数中使用了图像数组。toolView 是带有 UIToolbar 的 UIView。所以我想在屏幕上添加工具栏。是的,touchClass 是 UIScrollView 的子类。1.我明白了。我忘记发布了。谢谢。2.好的。我修改了这个。但是“ContentView”没有出现。

还有其他原因吗?

- (void)setPagingMode {

    CGSize pageSize = [self pageSize];
    NSUInteger page = 0;
    for (UIView *view in imageViewArray){
        [scrollView addSubview:view];
        view.frame = CGRectMake(pageSize.width * page++, 0, pageSize.width, pageSize.height);
    }

    scrollView.pagingEnabled = YES;
    scrollView.showsVerticalScrollIndicator = scrollView.showsHorizontalScrollIndicator = YES;
    scrollView.contentSize = CGSizeMake(pageSize.width * [imageViewArray count], pageSize.height);
    scrollView.contentOffset = CGPointMake(pageSize.width * currentPage, 0);    
    scrollViewMode = ScrollViewModePaging;
}
于 2010-06-07T06:11:32.020 回答
0

来源不清楚。你永远不会在 UIImageView 中使用数组。没有什么是 toolView 等信息...请提供更详细的来源。是touchClass的子类UIScrollView吗?

我在您的代码中注意到的内容:

  1. 你不释放imageand imageView。所有这些图像 imageViews 都将被泄露。在循环结束时,您应该添加[imageView release];[image release];
  2. 我不认为发送[self addSubview:contentView];尝试使用是个好主意[self.view addSubview:contentView];
于 2010-06-03T11:46:35.563 回答