首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为我的iOS应用程序构建一个启动程序?

如何为我的iOS应用程序构建一个启动程序?
EN

Stack Overflow用户
提问于 2012-09-24 22:21:29
回答 2查看 833关注 0票数 0

我正在为我的应用程序建立一个主页启动程序.就像来自Three20的那个。

我不想重新发明轮子,但是像Three20这样的解决方案并不是我正在寻找的:它们没有更新到最新的iOS系统或设备(视网膜、ARC、iOS 5/6),而且它们所做的远远超过我所需要的(我基本上需要一组带有标签的按钮,可以在设备旋转时旋转)。

现在,我正在尝试构建一个2x3按钮网格,在设备旋转时旋转,但是代码看起来非常糟糕,我需要添加iPhone5支持。

代码语言:javascript
复制
- (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);
    }
}

“放置材料,旋转它”是构建这种组件的唯一方法吗?还有别的选择吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-30 20:54:05

将按钮和标签放在视图中。然后,在旋转时,必须重新排列视图。

此外,您可以使用一个for来重新排列它们,所以您可以使用一些代码来获得这种效果。

代码语言:javascript
复制
-(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

代码语言:javascript
复制
-(void)viewWillLayoutSubviews {
        [self setScreenIconsToInterfaceRotation:[[UIApplication sharedApplication] statusBarOrientation]];
    }

和ios5

代码语言:javascript
复制
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {

    [self setScreenIconsToInterfaceRotation:toInterfaceOrientation]; 

}
票数 1
EN

Stack Overflow用户

发布于 2012-09-30 20:50:15

您可能需要自己编写代码,但是这里有一个非常棒的开源启动程序:

https://github.com/fieldforceapp/openspringboard

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12573761

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档