UIApplicationDelegate
에는 이러한 두 가지 방법이 있습니다.
- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame; // in screen coordinates
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame;
그리고 Notifications
도 있습니다.
UIApplicationWillChangeStatusBarFrameNotification
UIApplicationDidChangeStatusBarFrameNotification
하지만 앱을 시작할 때 게시되지 않으므로 권장하지 않습니다.
시뮬레이터에는이를 테스트 할 수있는 유용한 도구가 있습니다.
Hardware->Toggle In-Call Status Bar
구현하려면 해당 방법을 AppDelegate.m
파일에 구현해야합니다. 상태 막대가 높이를 바꿀 때 호출됩니다. 그 중 하나는 변경 전후에 호출됩니다.
변경이 발생할 때 ViewController
에 알림을 보내려는 경우 하나의 옵션은 알림을 보내는 것입니다. 이
처음처럼, 다음 AppDelegate.h
@property (assign, nonatomic) CGRect currentStatusBarFrame;
에이 속성을 추가 willChangeStatusBarFrame
AppDelegate.m
에
- (void) application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame
{
self.currentStatusBarFrame = newStatusBarFrame;
[[NSNotificationCenter defaultCenter] postNotificationName:@"Status Bar Frame Change"
object:self
userInfo:@{@"current status bar frame": [NSValue valueWithCGRect:newStatusBarFrame]}];
}
구현 그리고 우리는 우리의 Status Bar Frame Checker
의 기본으로 완료됩니다. 상태 표시 줄 프레임을 알아야하는 ViewController
에 구현 한 다음 부분입니다.
상태 표시 줄의 프레임을 취득 할 때마다, 당신이 그렇게
[(AppDelegate*)[[UIApplication sharedApplication] delegate] currentStatusBarFrame]
좋아한다 그리고이 변경 될 때 통지를, ViewDidLoad
방법이를 추가합니다.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(statusBarFrameChanged:)
name:@"Status Bar Frame Change"
object:[[UIApplication sharedApplication] delegate]];
그리고 정답은 처음에 하드 코딩 된 숫자와 레이아웃을하고 자동 레이아웃을 사용하지 않는이 방법
- (void) statusBarFrameChanged:(NSNotification*)notification
{
CGRect newFrame = [[notification.userInfo objectForKey:@"current status bar frame"] CGRectValue];
NSLog(@"new height %f", CGRectGetHeight(newFrame));
// Here you do whatever you wanna do with the new height
}
을 구현, 자동 마스크의 크기를 조절하거나, 현재의 크기를 기준으로하여 조정 실제로 상태 표시 줄의 상태를 모니터링하기보다는 layoutSubviews에 있습니다. (예를 들어, 동일한 이유로 3.5 인치 디스플레이에서 OP 코드가 작동하지 않습니다.) –
가로 모드에서이 작업을 수행하는 방법에 대한 의견 가로 모드에서 상태 표시 줄은 높이를 변경하지 않으므로 프레임이 변경되었습니다 알림이 호출되지 않습니다. – MusiGenesis
UIApplicationWillChangeStatusBarFrameNotification을 사용하여 "상태 표시 줄 프레임 변경"을 변경하려고한다고 생각합니다. – kevinl