8

私の目標は、iPhone アプリ (寸法 320*20 ピクセル) の上部にあるステータス バーの上に非表示のボタンを描画することです。

何を試しても、何かバグがあります:

  1. たとえば、新しいビューを作成しようとしました。ビューをアプリの一番上に配置したい場合、ステータスバーの前ではなく、常にステータスバーの後ろに消えます!

  2. Stackoverflow で別の素晴らしいアイデアを見つけました: StatusBar を含む他のすべてのビューの上に UIView を追加 する 2 つ目の UIWindow が推奨されていなくても、実装しようとしました。問題に気付くまでは、思い通りに機能していました。必要なときにキーボードが表示されなくなったのです (たとえば、テキスト ボックスをクリックしたときなど)。

どうすればこれを修正できますか? または、私の問題に対するより良いアプローチがありますか? これは、2 番目のウィンドウを作成するための私のコードです。

// Create window
statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)];
statusWindow.windowLevel = UIWindowLevelStatusBar;
[statusWindow makeKeyAndVisible];

// Create statusBarButton
statusBarButton = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect buttonFrame2 = statusBarButton.frame;
buttonFrame2.size = CGSizeMake(320,20);
statusBarButton.frame = buttonFrame2;
[statusBarButton addTarget:self action:@selector(goTop) forControlEvents:UIControlEventTouchUpInside]; 

// Place button into the new window
[statusWindow addSubview:statusBarButton];
4

4 に答える 4

9

AppDelegate ファイル内

self.window.windowLevel = UIWindowLevelStatusBar;

または他のクラスで

[AppDelegate appDelegate].window.windowLevel = UIWindowLevelStatusBar;

ステータスバーを再び一番上にしたい場合は、設定できます

self.window.windowLevel = UIWindowLevelNormal;
于 2014-06-05T13:59:55.613 に答える
8

-[UIWindow makeKeyAndVisible]のドキュメント:

これは、レシーバーをメインウィンドウにして、他のウィンドウの前に表示するための便利な方法です。UIViewの継承されたhiddenプロパティを使用して、ウィンドウを非表示および表示することもできます。

「キーウィンドウ」は、特定の入力イベントを取得するウィンドウです。非キーウィンドウのテキストフィールドが機能しない場合があります。できることは2つあります。

  • その後、古いキーウィンドウで[windowmakeKeyAndVisible]を呼び出します
  • 代わりに設定statusWindow.hidden = NOしてください(ただし、デフォルトで非表示になる理由はわかりません)。-makeKeyAndVisibleのように、「他のウィンドウの前に表示する」ことはできないと思います。Windowsには、IIRCで-bringSubviewToFront:を呼び出すことができるスーパービューがありません。
于 2010-11-23T04:29:40.883 に答える
7

他のユーザーがこれを実装したい場合、ここで私の解決策:

// Create window
statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(0,0,320,20)];
statusWindow.windowLevel = UIWindowLevelStatusBar;
// Dont make the statusWindow keyWindow or the keyboard won't work!
// [statusWindow makeKeyAndVisible];

// Create statusBarButton
statusBarButton = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect buttonFrame2 = statusBarButton.frame;
buttonFrame2.size = CGSizeMake(320,20);
statusBarButton.frame = buttonFrame2;
[statusBarButton addTarget:self action:@selector(goTop) forControlEvents:UIControlEventTouchUpInside]; 

// Place button into the new window
[statusWindow addSubview:statusBarButton];

// Instead, add this:
[window makeKeyAndVisible]; // has to be main window of app
statusWindow.hidden = NO; // without this the statusWindow won't appear
于 2010-11-23T23:30:18.867 に答える
0

試す:

[self.view bringSubviewToFront:statusWindow];

ただし、ステータスバーの前にビューを表示することは可能ではないと思います。

于 2010-11-23T02:24:20.933 に答える