在做iOS6和iOS7,以及3.5寸和4寸屏幕适配的时候遇到的frame的问题:
经过验证在viewcontroller上的self.view的坐标在有无系统navigationbar时的变化:
mainScreen: 568 4英寸
iOS7.1 -------- 无navigationbar: self.view(0,0,320,568)
-------- 有navigationbar: self.view(0,0,320,568) 坐标是基于navigationbar下方开始计算
iOS6.1 -------- 无navigationbar: self.view(0,20,320,548)
-------- 有navigationbar: self.view(0,20,320,548) 坐标是基于navigationbar下方开始计算
mainScreen: 480 3.5英寸
iOS7.1 -------- 无navigationbar: self.view(0,0,320,480)
-------- 有navigationbar: self.view(0,0,320,480) 坐标是基于navigationbar下方开始计算
iOS6.1 -------- 无navigationbar: self.view(0,20,320,460)
-------- 有navigationbar: self.view(0,20,320,460)坐标是基于navigationbar下方开始计算
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
[self setNavgationBackground];
[self addNavLeftButtonTitle:@"返回"];
backView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, mainScreenWidth, mainScreenHeight)];
[self.view addSubview:backView];
contentView = [[UIView alloc] initWithFrame:CGRectMake(0, knavigationHeight, 320, mainScreenHeight-ktabbarHeight-knavigationHeight)];
[contentView setUserInteractionEnabled:YES];
[contentView setBackgroundColor:[UIColor clearColor]];
[backView addSubview:contentView];
}
#define kContentViewHeight mainScreenHeight-ktabbarHeight-knavigationHeight
#define kstatusBar (k_IS_IOS7?20:0)
#define ktabbarHeight (self.tabBarController.tabBar.hidden?0:45)
#define khasNavigationbar (self.navigationController.navigationBar.hidden?0:65)
#define knavigationHeight (k_IS_IOS7?(khasNavigationbar?0:65):(khasNavigationbar?0:45))