当我在我的iPhone中打开人员HOT SPOT时,我的应用程序的屏幕向下移动,我正在加载子视图。但在其他屏幕上却没有发生。它只发生在我加载子视图的屏幕上。所以有人能告诉我可能是什么问题吗?任何帮助将不胜感激。
答案 0 :(得分:2)
每当出现热点或其他通知时,statusBarFrame将变为40px高。
CGRect rect;
rect = [[UIScreen mainScreen] bounds]; // Get screen dimensions
NSLog(@"Bounds: %1.0f, %1.0f, %1.0f, %1.0f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
rect = [[UIScreen mainScreen] applicationFrame]; // Get application frame dimensions (basically screen - status bar)
NSLog(@"App Frame: %1.0f, %1.0f, %1.0f, %1.0f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
rect = [[UIApplication sharedApplication] statusBarFrame]; // Get status bar frame dimensions
NSLog(@"Statusbar frame: %1.0f, %1.0f, %1.0f, %1.0f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
答案 1 :(得分:2)
您可以处理UIApplicationWillChangeStatusBarFrameNotification
和UIApplicationDidChangeStatusBarOrientationNotification
通知,这些通知会告诉您状态栏的新大小。避免对任何内容进行硬编码(例如40pt),而是从通知中获取新的状态栏框架。
如果您只需要高度,可以轻松地将其拉出来。如果您需要对状态栏框架执行更复杂的操作,则必须将其从屏幕坐标转换为您自己的视图坐标系(例如,如果您有全屏布局视图控制器并需要在其下面放置内容) :
- (void)statusBarFrameWillChangeNotification:(NSNotification *)notification
{
NSValue *rectValue = notification.userInfo[UIApplicationStatusBarFrameUserInfoKey];
CGRect statusBarFrame = [rectValue CGRectValue];
// if you just need the height, you can stop here
// otherwise convert the frame to our view's coordinate system
UIWindow *targetWindow = self.view.window;
// fromWindow:nil here converts from screen coordinates to the window
CGRect statusBarFrameWindowCoords = [targetWindow convertRect:statusBarFrame
fromWindow:nil];
CGRect frameRelativeToOurView = [self.view convertRect:statusBarFrameWindowCoords
fromView:targetWindow];
// ...
}
在iOS 7中,转换坐标尤为重要,因为默认情况下,所有视图控制器都具有全屏布局。
答案 2 :(得分:0)
状态栏会扩大并变大20像素,状态栏的位置不会改变,只会改变大小。我认为没有bool,但你可以检查是否
statusbarframe.size.height>20