より良い解決策:
a) 睡眠をとりましょう。
b) あなたが眠っている間に'UIBarStyleBlackTranslucent'を使用することは推奨されていないので、代わりに次のようにしてください:
- Interface Builder で MainWindow.xib を開き、「Tab Bar Controller」内の「Navigation Controller」内の「UINavigationBar」項目を選択し、「Style」を半透明ではなく「Black Opaque」に変更します。
UITableViewController クラス ファイルに次のように記述します。
- (void)viewWillDisappear:(BOOL)animated {
self.navigationController.navigationBar.translucent = YES; /* Yes, go underneath the Navigation Bar elsewhere if you want to. */
[super viewWillDisappear:animated];
}
- (void)viewWillAppear:(BOOL)animated {
self.navigationController.navigationBar.translucent = NO; /* No going underneath the Navigation Bar. Problem solved! */
...
[super viewWillAppear:animated];
}
c) 恥ずかしい思いをするのをやめて、睡眠が武器庫のもう 1 つの便利なコーディング テクニックであることを実感してください。;p
正しい解決策の手がかり:
「ナビゲーション コントローラーは、不透明なナビゲーション バーの下にコンテンツを表示しません。」
「ナビゲーション コントローラーの半透明のプロパティを YES に設定します。これにより、コンテンツをナビゲーション バーの下に重ねることができます。」
参照: developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/NavigationControllers/NavigationControllers.html
参照: developer.apple.com/iphone/library/documentation/UIKit/Reference/UINavigationBar_Class/Reference/UINavigationBar.html#//apple_ref/occ/instp/UINavigationBar/translucent
UIBarStyle さまざまなタイプのビューのスタイルの外観を定義します...
UIBarStyleBlackTranslucent = 2, // 非推奨
代わりに UIBarStyleBlack を使用し、translucent プロパティを YES に設定してください。
http://developer.apple.com/iphone/library/documentation/uikit/reference/UIKitDataTypesReference/Reference/reference.html
寝る前に、 「ハードウェイ」を修正しました...
- (void)correctFrame:(UIView *)viewWithWrongFrame {
CGRect correctedFrame = [[viewWithWrongFrame superview] frame];
correctedFrame.size.height = correctedFrame.size.height - self.navigationController.navigationBar.frame.size.height; /* Height without Navigation Bar */
correctedFrame.origin.y = correctedFrame.origin.y + self.navigationController.navigationBar.frame.size.height; /* Origin below Navigation Bar */
[viewWithWrongFrame setFrame:correctedFrame];
}
- (void)viewDidLoad {
[super viewDidLoad];
...
[self correctFrame:[self.navigationController.view.subviews objectAtIndex:0]]; /* Correct the frame so it is after the Navigation Bar */
[self.tableView setContentInset:UIEdgeInsetsMake(-self.navigationController.navigationBar.frame.size.height, 0, 0, 0)]; /* Eliminate initial blank space at top.*/
...
}
- (void)cleanDisplay {
[self.tableView setContentInset:UIEdgeInsetsZero]; /* Fix difference between horizontal and vertical orientation. */
...
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
[self correctFrame:[self.navigationController.view.subviews objectAtIndex:0]]; /* Correct the frame so it is after the Navigation Bar */
/* Clean the display after turning... */
[self performSelectorOnMainThread:@selector(cleanDisplay) withObject:nil waitUntilDone:NO];
}
- (void)viewWillAppear:(BOOL)animated {
...
[self performSelectorOnMainThread:@selector(cleanDisplay) withObject:nil waitUntilDone:NO];
...
}
失敗したアプローチには次のものが含まれていることに注意してください。
Interface Builder を使用して、UIView 内に UITableView を埋め込みます。すべてが自動的に最大の高さにサイズ変更されたため、機能しませんでした。サイズ変更 [self.tableView スーパービュー].frame = CGRectInset([self.tableView スーパービュー].frame, 44, 44); または .bounds は効果がなく、self.tableView.frame も .bounds も効果がありませんでした。
self.navigationController.view.frame = CGRectInset(self.navigationController.view.frame、20、44); テーブルを含むビューのサイズを実際に変更しました。明らかに、サブビューをそれに変更すると、元の問題が修正されます。
さらに上のアプローチで修正しました。ただし、他の画面に前後に移動する前に、要素が他の場所に移動しないように、変更を通常に戻す必要があります。