[英]supporting iphone 5 screen size
注意:在旧的屏幕尺寸上一切正常,但是在新的iphone屏幕(640x1136)上,一切都可能变差
这是应用程序委托初始化并显示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];
您可以从下面的图像中看到,导航栏位于其中的灰色栏。 带有箭头按钮的文本“星期二30 Apr ....”应占据该灰色区域,而不是顶部的2个单元格。
如果发现自己设置了导航控制器/导航栏的框架,则说明您在做错事。
大多数时候,您甚至都不需要设置视图控制器视图的框架。
您的应用程序委托不必比这更复杂:
- (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;
}
这很可能是您RootViewController笔尖中的设置。 对于左侧“对象”列表中的第一个视图,您可能已经设置了“顶栏”属性。
我最终用创建了单独的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]];
}
并且在projectname.pch文件中将IS_IPHONE_RETINA
定义为
#define IS_IPHONE_RETINA ([[UIScreen mainScreen] bounds].size.height == 568 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.