2015-01-07 1 views
0

주 화면에 로고가 포함되어 있고 세로로 2x3 및 가로로 3x2의 그리드에 레이아웃 된 6 개의 버튼이있는 앱이 있습니다.단추가 그리드에 배치 된보기 컨트롤러를 만드는 방법은 무엇입니까?

자동 레이아웃을 사용하여, 나는 제대로 올바르게 로고 (uiumage)과 uicollectionview을 배치 할 수 있습니다, 그들은 정확하게 배치하고, 장치가 회전을 변경 좋게 경우에도이 작동합니다. 로딩 후

: After loading the VC

전환 후 그러나, 회전 변화가 제대로 밖으로 누워되지 않습니다

-(void)viewDidLoadImpl{ 
self.navCollectionView.delegate = self; 
self.navCollectionView.dataSource = self; 
titlesArray = [NSArray arrayWithObjects: 
       @"Meine Hunde", 
       @"Füttern", 
       @"Einstellungen", 
       @"Fragen & Antworten", 
       @"Über diese App", 
       @"Rechtliches", nil]; 
seguesArray = [NSArray arrayWithObjects: 
       @"dogs", 
       @"feed", 
       @"settings", 
       @"faq", 
       @"about", 
       @"law", nil]; 
imagesArray = [NSArray arrayWithObjects: 
       [UIImage imageNamed:@"hunde_button"], 
       [UIImage imageNamed:@"fuettern_button"], 
       [UIImage imageNamed:@"einstellungen_button"], 
       [UIImage imageNamed:@"fragen_button"], 
       [UIImage imageNamed:@"ueber_button"], 
       [UIImage imageNamed:@"rechtlich_button"], nil]; 
imagesHoverArray = [NSArray arrayWithObjects: 
       [UIImage imageNamed:@"hunde_button_hover"], 
       [UIImage imageNamed:@"fuettern_button_hover"], 
       [UIImage imageNamed:@"einstellungen_button_hover"], 
       [UIImage imageNamed:@"fragen_button_hover"], 
       [UIImage imageNamed:@"ueber_button_hover"], 
       [UIImage imageNamed:@"rechtlich_button"], nil]; 
RDHCollectionViewGridLayout *layout = [RDHCollectionViewGridLayout new]; 
layout.lineItemCount = 2; 
layout.lineDimension = 0; 
layout.scrollDirection = UICollectionViewScrollDirectionVertical; 
layout.sectionsStartOnNewLine = YES; 
[self.navCollectionView setCollectionViewLayout:layout]; 
} 


    #pragma mark - UICollection View Datasource 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ 
return 6; 
} 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 
static NSString *identifier = @"Cell"; 
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 
UILabel *label = (UILabel *)[cell viewWithTag:10]; 
label.text = [titlesArray objectAtIndex:indexPath.row]; 
UIButton *button = (UIButton *)[cell viewWithTag:20]; 
// do something with the button 
return cell; 
} 

#pragma mark - UICollectionViewDelegatFlowLayout 
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ 

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; 
if(orientation == UIInterfaceOrientationLandscapeLeft) { 
    // orientation is landscape left 
    CGSize s = {100,200}; 
    return s; 
} else if(orientation == UIInterfaceOrientationLandscapeRight) { 
    // orientation is landscape right 
    CGSize s = {100,200}; 
    return s; 
} else if(orientation == UIInterfaceOrientationMaskPortrait) { 
    // orientation is portrait 
    CGSize s = {100,100}; 
    return s; 
} else if(orientation == UIInterfaceOrientationMaskPortraitUpsideDown) { 
    // orientation is portrait upsidedown 
    CGSize s = {100,100}; 
    return s; 
} else { 
    CGSize s = {100,100}; 
    return s; 
} 
} 

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 
if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation ==  UIInterfaceOrientationPortrait) { 

    RDHCollectionViewGridLayout *layout = [RDHCollectionViewGridLayout new]; 
    layout.lineItemCount = 2; 
    layout.lineDimension = 0; 
    layout.scrollDirection = UICollectionViewScrollDirectionVertical; 
    layout.sectionsStartOnNewLine = YES; 
    [self.navCollectionView setCollectionViewLayout:layout]; 
} else { 
    RDHCollectionViewGridLayout *layout = [RDHCollectionViewGridLayout new]; 
    layout.lineItemCount = 3; 
    layout.lineDimension = 0; 
    layout.scrollDirection = UICollectionViewScrollDirectionVertical; 
    layout.sectionsStartOnNewLine = YES; 
    [self.navCollectionView setCollectionViewLayout:layout]; 
} 
} 

, 스크린 샷을 참조

:

내가합니다 (RDHCollectionViewGridLayout 클래스를 사용하여) 가지고 무엇을 가로 방향 : After switching to landscape

다시 세로로 전환 한 후 : enter image description here

콜렉션 뷰를 사용하는 것이 올바른 방법인지 잘 모르겠습니까? 내가 정적 tableview 같은 것을 사용하는 것이 좋겠지 만, 이건 내게 단 하나의 열을 제공합니까?

+0

원하는 경우 표보기를 사용할 수 있습니다. 사용자 정의 테이블보기 셀에 두 개 또는 세 개의 버튼을 추가하여 격자 모양으로 만들 수 있습니다. 나는 그런 식으로 작업을 수행하는 경우에, 나는 아마 두 개의 세포 프로토 타입, 두 개의 버튼과 1 ~ 3과 하나 만들고, 당신이 방향에 따라 필요로하는 하나를 큐에서 제거 할 것 (그래서 동적 테이블이 아닌 정적을 사용합니다). – rdelmar

답변

0

컬렉션보기 (즉, 2 차원 표)가 필요합니다. 격자를 처음로드 할 때 각 셀의 크기는 100 x 100입니까? 인터페이스 빌더에 표시 한 내용입니까? 처음에는 적절하게 크기를 조정하고 가로 방향으로 조정하면 조정 한 다음 세로 방향으로 되돌릴 때 잘못 조정할 수 있습니다.

-1

내 솔루션은 맞도록 값을 계산 RDHCollectionViewGridLayout 및 UICollectionViewDelegateFlowLayout 클래스를 사용하고 그 방법을 사용하지 않는 것입니다.

관련 문제