0

アプリのホームページランチャーを構築しようとしています... Three20のもののようなもの。

ここに画像の説明を入力

車輪の再発明はしたくありませんが、Three20 のようなソリューションは私が探しているものではありません。それらは最新の iOS システムまたはデバイス (Retina、ARC、iOS5/6) に更新されておらず、機能をはるかに超えています。必要です(基本的に、デバイスの回転で回転するラベル付きのボタンのセットが必要です)。

現在、デバイスの回転で回転する 2x3 ボタン グリッドを構築しようとしていますが、コードはかなりお粗末に見え、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);
    }
}

この種のコンポーネントを構築する唯一の方法は、「配置して回転させる」アプローチですか? 代替手段はありますか?

4

2 に答える 2

2

これを自分でコーディングしたいかもしれませんが、素晴らしいオープンソースのランチャーがここにあります:

https://github.com/fieldforceapp/openspringboard

于 2012-09-30T20:50:15.507 に答える
1

ボタンとラベルをビュー内に配置します。次に、回転時にビューだけを再配置する必要があります。

さらに、 a を使用し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]; 

}
于 2012-09-30T20:54:05.013 に答える