Вы можете узнать, когда это произойдет, используя следующие методы UIApplicationDelegate:
- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame {
NSLog(@"willChangeStatusBarFrame : newSize %f, %f", newStatusBarFrame.size.width, newStatusBarFrame.size.height);
}
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)newStatusBarFrame {
NSLog(@"didChangeStatusBarFrame : newSize %f, %f", newStatusBarFrame.size.width, newStatusBarFrame.size.height);
}
Кроме того, вы можете зарегистрироваться для получения уведомления в подклассе UIViewController:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameChanged:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarFrameWillChange:) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
}
- (void)statusBarFrameWillChange:(NSNotification*)notification {
NSValue* rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
CGRect newFrame;
[rectValue getValue:&newFrame];
NSLog(@"statusBarFrameWillChange: newSize %f, %f", newFrame.size.width, newFrame.size.height);
// Move your view here ...
}
- (void)statusBarFrameChanged:(NSNotification*)notification {
NSValue* rectValue = [[notification userInfo] valueForKey:UIApplicationStatusBarFrameUserInfoKey];
CGRect oldFrame;
[rectValue getValue:&oldFrame];
NSLog(@"statusBarFrameChanged: oldSize %f, %f", oldFrame.size.width, oldFrame.size.height);
// ... or here, whichever makes the most sense for your app.
}