iPhone의 StatusBar에보기 추가
크기 (320 x 20)의 상태 표시 줄에 UIView를 추가 할 수 있습니까? 상태 표시 줄을 숨기고 싶지 않고 상태 표시 줄 위에 만 추가하고 싶습니다.
기존 상태 표시 줄 위에 고유 한 창을 만들어 쉽게 수행 할 수 있습니다.
UIWindow
다음 재정의를 사용하여의 간단한 하위 클래스를 만듭니다.initWithFrame:
@interface ACStatusBarOverlayWindow : UIWindow {
}
@end
@implementation ACStatusBarOverlayWindow
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Place the window on the correct level and position
self.windowLevel = UIWindowLevelStatusBar+1.0f;
self.frame = [[UIApplication sharedApplication] statusBarFrame];
// Create an image view with an image to make it look like a status bar.
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:self.frame];
backgroundImageView.image = [UIImage imageNamed:@"statusBarBackground.png"];
[self addSubview:backgroundImageView];
[backgroundImageView release];
// TODO: Insert subviews (labels, imageViews, etc...)
}
return self;
}
@end
예를 들어 이제 애플리케이션의 뷰 컨트롤러에서 새 클래스의 인스턴스를 만들고 표시 할 수 있습니다.
overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectZero];
overlayWindow.hidden = NO;
- (void)makeKeyAndVisible
또는 이와 유사한 것을 사용하여 창 키 상태를 엉망으로 만드는 것에 유의하십시오 . 메인 창 ( UIWindow
애플리케이션 델리게이트의)을 느슨한 키 상태로 만들면 상태 표시 줄을 탭할 때 스크롤 뷰를 맨 위로 스크롤하는 데 문제가 발생합니다.
Reeders 상태 표시 줄 오버레이를 모방 한 정적 라이브러리를 작성했습니다. https://github.com/myell0w/MTStatusBarOverlay에서 찾을 수 있습니다.
현재 iPhone 및 iPad, 기본 및 불투명 한 검은 색 상태 표시 줄 스타일, 회전, 3 가지 다른 애니메이션 모드, 히스토리 추적 및 더 많은 기능을 지원합니다!
자유롭게 사용하거나 개선을 위해 Pull Request를 보내주세요!
모든 답변이 작동하는 것처럼 보이지만 iOS6.0에서는 다음 문제가 있습니다.
1 / 회전이 나빠 보입니다.
2 / 창 (상태 표시 줄은 일종의 창) 필요한 rootViewController
myell0w의 답변을 사용 하고 있지만 회전이 좋지 않습니다. 추가 창 하나를 제거하고 AppDelegate에서 UIWindow를 사용하여 상태 표시 줄을 구현했습니다. 이 솔루션은 하나의 UIViewController-app에만 괜찮을 수 있습니다.
다음 방법으로 구현했습니다.
1 / ApplicationDelegate에서 :
self.window.windowLevel = UIWindowLevelStatusBar + 1;
self.window.backgroundColor = [UIColor clearColor];
self.window.rootViewController = _journalController;
2 / 사용자 정의 UIView를 만들고 필요한 모든 것을 내부에 구현합니다. 터치 가능한 상태 표시 줄의 예 :
@interface LoadingStatusBar : UIControl
컨트롤러보기를 쉽게 만들고 추가 할 수 있습니다.
_loadingBar = [[LoadingStatusBar alloc] initWithFrame:topFrame];
[self addSubview:_loadingBar];
3 / 컨트롤러 뷰를 추가 할 때 약간의 마술 (initWithFrame에서 :)
CGRect mainFrame = self.bounds;
mainFrame.origin.y = 20;
self.bounds = mainFrame;
컨트롤러보기에는 콘텐츠보기와 상태 표시 줄보기의 두 가지보기가 있습니다. 상태 표시 줄을 표시하거나 원할 때 숨길 수 있습니다. 콘텐츠보기의 프레임은 다음과 같습니다.
_contentView.frame = CGRectMake(0, 20, self.bounds.size.width, self.bounds.size.height);
4 / 그리고 여기 마지막 마법 :) 터치 불가능한 영역에서 터치를 감지하려면 다음을 사용했습니다.
-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
if (point.y < 20) return _loadingBar;
return [super hitTest:point withEvent:event];
}
현재로서는 iPad / iPhone 및 모든 iOS에서 4 ~ 6까지 잘 작동합니다.
"이 코멘트를 할 수 없습니다"를 무시하기 위해 ...
나는 방법을 모르지만 그것이 가능하다는 것을 압니다. Reeder라는 피드 리더 앱이이를 수행합니다.
스크린 샷에서 볼 수 있듯이 Reeder는 화면 오른쪽 상단에 작은 점을 표시합니다. 탭할 때. 막대를 다시 탭하여 작게 만들 때까지 전체 상태 표시 줄을 채 웁니다.
First of all, a big thank you to @Martin Alléus for providing the code for this implementation.
I'm just posting for a problem that I faced and the solution I used, as I believe others might experience the same issue.
If the App is started while an call is in place, the status bar height will be 40 pixels and this means that the custom status bar will be initialized with that height. But if the call is ended while you are still in the app, the status bar height will remain still 40 pixels and it will look weird.
So the solution is simple: I've used the Notification center to subscribe to the status bar frame change delegate of the app and adjust the frame:
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame {
//an in call toggle was done
//fire notification
[[NSNotificationCenter defaultCenter] postNotificationName:kStatusBarChangedNotification object:[NSValue valueWithCGRect:oldStatusBarFrame]];
}
And in the ACStatusBarOverlayWindow we subscribe to the notification:
-(id)initWithFrame:(CGRect)frame
{
if ((self = [super initWithFrame:frame]))
{
// Place the window on the correct level & position
self.windowLevel = UIWindowLevelStatusBar + 1.0f;
self.frame = [UIApplication sharedApplication].statusBarFrame;
self.backgroundColor = [UIColor blackColor];
//add notification observer for in call status bar toggling
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarChanged:) name:kStatusBarChangedNotification object:nil];
}
return self;
}
and our code to adjust the frame:
- (void)statusBarChanged:(NSNotification*)notification {
//adjust frame...
self.frame = [UIApplication sharedApplication].statusBarFrame;
//you should adjust also the other controls you added here
}
(가) kStatusBarChangedNotification
내가 쉽게 referrence에 사용했습니다 단지 상수, 당신은 단순히 문자열로 교체, 또는 전 세계적으로 상수를 선언 할 수 있습니다.
참고 URL : https://stackoverflow.com/questions/2833724/adding-view-on-statusbar-in-iphone
'Nice programing' 카테고리의 다른 글
urllib2의 시간 초과 처리? (0) | 2020.11.27 |
---|---|
Rails : Partials는 인스턴스 변수를 인식해야합니까? (0) | 2020.11.26 |
Linux에서 홈 디렉토리 가져 오기 (0) | 2020.11.26 |
RSpec stubbed 메서드가 순서대로 다른 값을 반환 할 수 있습니까? (0) | 2020.11.26 |
웹 애플리케이션에서 Log4Net 구성 (0) | 2020.11.26 |