2012-09-24 53 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]; 

} 
相关问题