2012-06-14 2 views
0

AQGridView를 사용하여 약 21 개의 항목이있는 이미지 갤러리를 만듭니다. 사용자가 볼 수 있도록이 목록/scrollview 상단에 앱 로고와 이름이 포함 된보기를 추가하고 싶지만 이미지를 보면서 스크롤하면 이름과 로고 스크롤이있는보기가 표시됩니다. 이전에 이와 비슷한 것을 구현 한 사람이 있습니까?AQGridView의 위쪽에보기 추가 ScrollView

@skram 덕분에 로고를 추가 할 수 있었지만 이제 이미지는 이미지의 첫 번째 행을 차단합니다.

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

시뮬레이터의 스크린 샷이다 나는 로고를 정의하고있는 gridview에 추가 할 경우 여기에

입니다

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

희망이 있습니다.

EDIT : 모든 이미지가 로고와 겹치지 않도록 AQGridView에 로고를 첫 번째 하위보기로 추가하여 답변을 편집합니다. 대신 가정, [_grid addSubview:logo]를 사용하는 이들 UIImageView의 사용은 다음과 같습니다 skram 버전 내가 gridViewHeader가 최선의 선택 나의 목적이 언급하고 싶었다 작업을 수행하는 동안

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

편집 mkral

BY 참조 코드 :

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를 삽입하는 것을 말하지 않습니까? – mkral