简体   繁体   中英

supporting iphone 5 screen size

Note: Everything worked fine on the older screen sizes however on the new iphone screens (640x1136) things are way to far down

here is the App Delegate initing and showing 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];

The RootViewController sets the frame for the 'navigationController' and a few other views before adding them to its view.

    //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];

You can see from the image below that the grey bar is there for the nav bar. The text "Tuesday 30 Apr...." with the arrow buttons should occupy that grey area and not 2 cells from the top.

在此处输入图片说明

If you find yourself setting the frame of your navigation controller / navigation bar, you're doing something wrong.

Most of the time, you don't even need to set the frame of your view controller's view either.

Your app delegate needn't be any more complicated than this:

- (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;
}

It will most likely be a setting in your RootViewController nib. For the first view in the "Objects" list on the left, you have probably set the Top Bar property.

I ended up creating separate xib files with

_iPhone_Retina

at end of the file name

Which also called for statements like this

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

and IS_IPHONE_RETINA is defined in the projectname.pch file as

#define IS_IPHONE_RETINA ([[UIScreen mainScreen] bounds].size.height == 568 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM