Iphone 将视图添加到AQGridView滚动视图的顶部
我正在使用AQGridView创建一个包含大约21个项目的图像库。我想在此列表/滚动视图的顶部添加一个包含应用程序徽标和名称的视图,这样用户可以看到它,但当他们滚动查看图像时,名称和徽标的视图会随之滚动。以前有人实现过类似的东西吗 多亏了@skram,我才能够添加徽标,但现在图像被第一行图像挡住了 这里是我定义徽标并将其添加到gridView的地方:Iphone 将视图添加到AQGridView滚动视图的顶部,iphone,ios,aqgridview,Iphone,Ios,Aqgridview,我正在使用AQGridView创建一个包含大约21个项目的图像库。我想在此列表/滚动视图的顶部添加一个包含应用程序徽标和名称的视图,这样用户可以看到它,但当他们滚动查看图像时,名称和徽标的视图会随之滚动。以前有人实现过类似的东西吗 多亏了@skram,我才能够添加徽标,但现在图像被第一行图像挡住了 这里是我定义徽标并将其添加到gridView的地方: self.gridView = [[AQGridView alloc] initWithFrame:CGRectMake(0, 0, 320,
self.gridView = [[AQGridView alloc] initWithFrame:CGRectMake(0, 0, 320, 367)];
UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"paramythLogoTest.png"]];
[logo setFrame:CGRectMake(0,0,logo.frame.size.width,logo.frame.size.height)];
[gridView addSubview:logo];
self.gridView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
self.gridView.autoresizesSubviews = YES;
self.gridView.delegate = self;
self.gridView.dataSource = self;
[self.view addSubview:gridView];
[self.gridView reloadData];
然后在此处加载图像:
- (AQGridViewCell *) gridView: (AQGridView *) aGridView cellForItemAtIndex: (NSUInteger) index
{
static NSString * PlainCellIdentifier = @"PlainCellIdentifier";
GridViewCell * cell = (GridViewCell *)[aGridView dequeueReusableCellWithIdentifier:@"PlainCellIdentifier"];
if ( cell == nil )
{
cell = [[GridViewCell alloc] initWithFrame: CGRectMake(3.333, 3.333, 100, 100)
reuseIdentifier: PlainCellIdentifier];
}
NSString *stringURL = [[featuredStories objectAtIndex:index] objectAtIndex:1];
NSURL *url = [NSURL URLWithString:stringURL];
[cell.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"example0.png"]];
cell.storyID = [[featuredStories objectAtIndex:index] objectAtIndex:0];\
return cell;
}
以下是模拟器的屏幕截图:
是的。您可以使用
addSubview:
轻松完成此操作。在AQGridView
实例上,添加UIImageView
作为子视图AQGridView
不过是一个子类的UIScrollView
,您可以在其上使用addSubview:
....
AQGridView *_grid;
....
UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo.png"]];
[logo setFrame:CGRectMake(0,0,logo.frame.size.width,logo.frame.size.height)]; // Set the Frame's position on where you want it in the grid.
[_grid addSubview:logo];
希望这有帮助
编辑:编辑答案以反映将徽标作为第一个子视图添加到AQGridView
,从而使所有图像与徽标重叠。不使用[\u grid addSubview:logo]
,假设这些是UIImageView
的用法:
[_grid insertSubview:logo belowSubview:(UIImageView*)[_grid.subviews objectAtIndex:0]];
由mkral编辑
虽然skram版本可以工作,但我想指出,出于我的目的,gridViewHeader是最好的选择,请参见代码:
UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"paramythLogoTest.png"]];
[logo setFrame:CGRectMake(0,0,logo.frame.size.width,logo.frame.size.height)];
[gridView setGridHeaderView:logo];
好的,很好,但它覆盖了图像。您知道需要在哪里设置偏移量吗?您可以使用
insertSubview:belowSubview
。这将做的是添加你的标志作为第一个对象在层中。之后的所有内容都将添加到上面的层上:[\u grid insertSubview:logo belowSubview:(UIImageView*)[\u grid.subviews objectAtIndex:0];假设它是一个
UIImageView`我对您的示例有点困惑,您不是说要在同一个徽标imageview下面插入徽标imageview吗?如果您的scrollview中已经有图像,则没有。它将获取已在滚动视图中的第一个项目,可能是其中一个图像。如果不是这样,每次添加新图像时,您可能必须执行sendSubviewToBack
Oh好的,我首先添加logo子视图。是否有类似afterCellsLoaded之类的AQGridView委托方法。