支持iphone 5屏幕尺寸

时间:2013-04-29 18:11:50

标签: iphone ios uinavigationcontroller

注意:在旧的屏幕尺寸上一切正常但是在新的iphone屏幕上(640x1136),事情可以向远处发展

此处是App Delegate初始化并显示myRootViewController

  myRootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];

    [myRootViewController.view setFrame:[[UIScreen mainScreen] applicationFrame]];

    //NSLog(@"rootviewcontroller1 frame %@", NSStringFromCGRect(myRootViewController.view.frame)); 
    //OUTPUTS: {{0, 0}, {320, 460}}

    [window addSubview:myRootViewController.view];

RootViewController在将“navigationController”和其他一些视图添加到视图之前设置框架。

    //NSLog(@"ogtest rootviewcontroller frame2 %@", NSStringFromCGRect(self.view.frame)); 
//OUTPUTS: {{0, 20}, {320, 548}}



  [navigationController.view setFrame:CGRectMake(0, 0, 320,528)];
//I have tried multiples variations including not setting it.

        loadingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        [loadingView setBackgroundColor:[UIColor clearColor]];
        UILabel *_loadingLable = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 80.0f, 20.0f)];
        _loadingLable.backgroundColor = [UIColor clearColor];
        _loadingLable.textColor = [UIColor whiteColor];
        _loadingLable.text = @"Loading...";
        [_loadingLable setCenter:CGPointMake(181.0f, 240.0f)];
        activityIndicatior = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        [activityIndicatior setCenter:CGPointMake(120.0f, 240.0f)];

        RoundedView *_roundedRectangle = [[RoundedView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 140.0f, 50.0f) roundedCorner:RoundedCornersTypeALL];
        _roundedRectangle.center = CGPointMake(160.0, 240.0);
        _roundedRectangle.rectColor = [UIColor blackColor];
        _roundedRectangle.alpha = 0.7;
        [loadingView addSubview:_roundedRectangle];
        [loadingView addSubview:activityIndicatior];
        [loadingView addSubview:_loadingLable];
        [_loadingLable release];
        [_roundedRectangle release];

        [loadingView setHidden:YES];

        [self.view addSubview:[navigationController view]];
        [self.view addSubview: loadingView];

您可以从下面的图片中看到导航栏上有灰色条。带有箭头按钮的文字“4月30日星期二......”应该占据那个灰色区域而不是顶部的2个单元格。

enter image description here

3 个答案:

答案 0 :(得分:1)

如果您发现自己设置了导航控制器/导航栏的框架,那么您做错了。

大多数情况下,您甚至不需要设置视图控制器视图的框架。

您的应用代表不需要比这更复杂:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self setWindow:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]];

    [[self window] setRootViewController:[[UINavigationController alloc] initWithRootViewController:[[RootViewController alloc] init]];

    [self.window makeKeyAndVisible];

    return YES;
}

答案 1 :(得分:0)

它很可能是RootViewController笔尖中的一个设置。对于左侧“对象”列表中的第一个视图,您可能已设置了“顶栏”属性。

答案 2 :(得分:0)

我最终用

创建单独的xib文件
  

_iPhone_Retina

在文件名末尾

还要求这样的陈述

if (IS_IPHONE_RETINA) {
                View = [[View alloc] initWithNibName:@"View_iPhone_Retina" bundle:[NSBundle mainBundle]];
            }else{
                View = [[View alloc] initWithNibName:@"View" bundle:[NSBundle mainBundle]];
            }

IS_IPHONE_RETINA在projectname.pch文件中定义为

#define IS_IPHONE_RETINA ([[UIScreen mainScreen] bounds].size.height == 568 )
相关问题