2012-06-14 20 views
0

我正在使用AQGridView創建一個包含約21個項目的圖像庫。我想將包含應用徽標和名稱的視圖添加到此列表/滾動視圖的頂部,以便用戶可以看到它,但當他們滾動查看圖像時,帶有名稱和徽標的視圖會隨之滾動。有沒有人實施過這樣的事情?將視圖添加到AQGridView的頂部ScrollView

感謝@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

回答

1

是的。你可以用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的第一個子視圖,使所有圖像重疊徽標。除了使用[_grid addSubview:logo],假設這些都是UIImageView的用途:

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

編輯由mkral

雖然斯克拉姆版本確實我想提一提,我的目的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]; 
+0

好吧,它的工作原理,但它覆蓋的圖像。你知道我需要設置偏移量嗎? – mkral

+0

你可以使用'insertSubview:belowSubview'。這將做的是添加您的標誌作爲圖層中的第一個對象。之後的所有內容都將添加到上面的圖層上:'[_grid insertSubview:logo belowSubview:(UIImageView *)[_ grid.subviews objectAtIndex:0]];假設它是一個'UIImageView' – skram

+0

我在你的例子中有點困惑你不是說要在同一個標​​識imageview下面插入標識imageview? – mkral