0

我正在使用 AQGridView 创建一个包含大约 21 个项目的图片库。我想在此列表/滚动视图的顶部添加一个包含应用程序徽标和名称的视图,以便用户看到它,但当他们滚动查看图像时,带有名称和徽标的视图会随之滚动。以前有没有人实施过这样的事情?

感谢@skram,我能够添加徽标,但现在图像被第一行图像挡住了。

这是我定义徽标并将其添加到 gridView 的地方:

 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;
}

这是模拟器的截图:

enter image description here

4

1 回答 1

1

是的。您可以使用addSubview:. 在您的AQGridView实例上,添加 aUIImageView作为子视图。AQGridView只不过是一个 subclassed 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];

希望这可以帮助。

EDIT: Editing Answer to reflect adding the logo as the first subview to the AQGridView so all images overlap the logo. Instead of using [_grid addSubview:logo], Assuming these are UIImageView's Use:

[_grid insertSubview:logo belowSubview:(UIImageView*)[_grid.subviews objectAtIndex:0]];

EDIT BY mkral

While skram version does work I wanted to mention that for my purposes the gridViewHeader is the best option, see code:

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]; 
于 2012-06-14T16:22:34.710 回答