帮帮我。 addSubview不起作用。 我想在scrollView上添加“ContentView”。 但“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];
}
答案 0 :(得分:1)
我在下面的函数中使用了图像数组。 toolView是带有UIToolbar的UIView。 所以我想在屏幕上添加工具栏。 是的,touchClass是UIScrollView的子类。 我明白了。我忘了发布这个。谢谢。 2.OK.我对此进行了修改。但“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;
}
答案 1 :(得分:0)
来源尚不清楚。
你永远不会在UIImageView中使用数组。没有信息什么是toolView等...
请提供更详细的来源。 touchClass
是UIScrollView
的子类吗?
我在你的代码中注意到了:
image
和imageView
。所有这些图像imageViews将被泄露。在循环结束时,您应添加[imageView release];
和[image release];
[self addSubview:contentView];
尝试使用[self.view addSubview:contentView];