2012-09-24 51 views
0

我試圖爲我的應用程序構建主頁啓動器... 類似於Three20中的一個。如何爲我的iOS應用程序構建啓動器?

enter image description here

我不想推倒重來,但像Three20解決方案是不是我在尋找:他們沒有更新到最新的iOS系統或設備(視網膜,ARC, iOS5/6),他們做的比我需要的要多得多(我基本上需要一組帶有旋轉設備旋轉標籤的按鈕)。

現在我想建立一個2×3格按鈕上裝置轉動而轉動,但代碼看起來很糟糕,我鋼需要添加iPhone5的支持...

- (void) updateLayoutForNewOrientation: (UIInterfaceOrientation) orientation { 

    if (UIInterfaceOrientationIsPortrait(orientation)) { 
     button1.frame = CGRectMake(20, 59, 130, 80); 
     button2.frame = CGRectMake(170, 59, 130, 80); 
     button3.frame = CGRectMake(20, 176, 130, 80); 
     button4.frame = CGRectMake(170, 176, 130, 80); 
     button5.frame = CGRectMake(20, 293, 130, 80); 
     button6.frame = CGRectMake(170, 293, 130, 80); 

     label1.frame = CGRectMake(20, 147, 130, 21); 
     label2.frame = CGRectMake(170, 147, 130, 21); 
     label3.frame = CGRectMake(20, 264, 130, 21); 
     label4.frame = CGRectMake(170, 264, 130, 21); 
     label5.frame = CGRectMake(20, 381, 130, 21); 
     label6.frame = CGRectMake(170, 381, 130, 21); 
    } else { 
     button1.frame = CGRectMake(20, 59, 130, 60); 
     button2.frame = CGRectMake(177, 59, 130, 60); 
     button3.frame = CGRectMake(328, 59, 130, 60); 
     button4.frame = CGRectMake(20, 155, 130, 60); 
     button5.frame = CGRectMake(177, 155, 130, 60); 
     button6.frame = CGRectMake(328, 155, 130, 60); 

     label1.frame = CGRectMake(20, 127, 130, 21); 
     label2.frame = CGRectMake(177, 127, 130, 21); 
     label3.frame = CGRectMake(328, 127, 130, 21); 
     label4.frame = CGRectMake(20, 223, 130, 21); 
     label5.frame = CGRectMake(177, 223, 130, 21); 
     label6.frame = CGRectMake(328, 223, 130, 21); 
    } 
} 

就是「地方東西,旋轉它「的方法來建立這種組件?有其他選擇嗎?

+0

決定一個按鈕的最小尺寸,計算有多少人你可以適應可用的矩形,把它分成一個網格,並做一些佈局。 –

+1

如果您僅針對iOS 6,請查看[UICollectionView](https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UICollectionView_class/Reference/Reference.html)... – Macmade

+0

謝謝,我正在研究它,但我更喜歡至少瞄準iOS 5. – Napolux

回答

1

把按鈕和視圖中的標籤。 然後,在旋轉時,您必須重新排列視圖。

此外,您可以使用for重新排列它們,因此您可以使用一些代碼來獲得該效果。

-(void)setScreenIconsToInterfaceRotation:(UIInterfaceOrientation)toInterfaceOrientation { 
    NSArray * viewsArray = [NSArray arrayWithObjects:view1,view2,view3,view4,view5,view6, nil]; 

    int currentIndex = 0; 

    for (UIView * currentView in ViewsArray) { 

     int x; 
     int y; 
     int xseparation = 20; 
     int yseparation; 
     int height; 
     int width = 130; 
     if (toInterfaceOrientation==UIDeviceOrientationPortrait || toInterfaceOrientation==UIDeviceOrientationPortraitUpsideDown) 
     { 

      x = currentIndex %2; 
      y = currentIndex /2; 
      height = 101; 
      if (currentIndex < 2) { 
       yseparation = 59; 
      } else { 
       yseparation = 16; 
      } 

     } else { 
      x = currentIndex %3; 
      y = currentIndex /3; 
      height = 81; 
      if (currentIndex < 3) { 
       yseparation = 59; 
      } else { 
       yseparation = 15; 
      } 

     } 

     [currentView setFrame:CGRectMake(x*width+((x+1)*xseparation), y*height+((y+1)*yseparation), width, height)]; 


     currentIndex++; 
     } 

} 

這是您的示例代碼

然後iOS6的

-(void)viewWillLayoutSubviews { 
     [self setScreenIconsToInterfaceRotation:[[UIApplication sharedApplication] statusBarOrientation]]; 
    } 

和iOS5的

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
    { 

    [self setScreenIconsToInterfaceRotation:toInterfaceOrientation]; 

} 
相關問題