IOS 当设置个人热点的时候,状态栏高度会由20像素变成40像素。

来源:互联网 发布:淘宝贷款逾期怎么办 编辑:程序博客网 时间:2024/05/16 15:11

UIApplicationWillChangeStatusBarFrameNotification,接这个系统通知会得到最新的statusBar的frame,根据最新的frame来调整视图。


// 在相应的ViewController 写适配方法
- (void)adapterstatusBarHeight{
// 之所以加这段代码,是因为当设置个人wifi热点等情况下,状态栏高度会由20像素变成40像素
// 导致底部的tab被往下挤掉一部分,所以这种情况下,tab的Y坐标就要向上移动20像素
CGRect statusBarRect = [[UIApplication sharedApplication] statusBarFrame];
int shouldBeSubtractionHeight = 0;
if (statusBarRect.size.height == 40) {
shouldBeSubtractionHeight = 20;
}
if ([[UIDevice currentDevice].systemVersion floatValue]>=7.0[[UIDevice currentDevice].systemVersion floatValue]<6.0) {
tabBar.frame = CGRectMake(0, __MainScreen_Height-49 - shouldBeSubtractionHeight , 320, 49);
}else{
tabBar.frame =CGRectMake(0, __MainScreen_Height-69 - shouldBeSubtractionHeight , 320, 49);
}
}

在AppDelegate的这个函数函数去调用
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
[[UIApplication sharedApplication] cancelAllLocalNotifications];
application.applicationIconBadgeNumber = 0;
[[mainViewController sharedmain] adapterstatusBarHeight];
}

0 0
原创粉丝点击