メニューボタン付きのナビゲーションコントローラーがあります。メニュー ボタンを押すと、現在のビュー (ナビゲーション バーを含む) が右にスライドし、メニューが同時に連続して左からスライドします。詳細は、以下のコード内のコメントで説明されています。
1つの点を除いて機能します。現在のビュー (この場合は「会話」) は、実装するコンテナー ビューに再度追加するときに、そのフレームを「y.min」=-20 に設定する必要があります。そうしないと、ナビゲーション バーの上に 20 ピクセルが存在します。ただし、y.min を -20 に設定すると、ビュー内のすべてが 20 ピクセル上に移動します。そのため、メニュー ボタンが押されると、現在のビューのすべてが突然 20 ピクセル上にジャンプします。
なぜこれが起こっているのか、これを修正する方法がわかりません。このすべてを行うためのより簡単な方法がある可能性もありますが、私はその方法を知りません.* (*私はサードパーティのファイルには興味がありません。これを自分で行う方法を学びたいです。)
コードは次のとおりです。
- (IBAction) showMenu:(id)sender
{
// get pointer to app delegate, which contains property for menu pointer
AppDelegate *appDelegate = getAppDelegate;
//create container view so that current view, along with its navigation bar, can be displayed alongside menu
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 548.0f)];
[container setBackgroundColor:[UIColor blueColor]];
//before presenting menu, create pointer for current view, to be used in completion routine
UIView *presenter = self.navigationController.view;
//present menu's VC. it is necessary to present its (table) VC, not just add its view, to retain the functionality of its cells
[self presentViewController:appDelegate.menuVC animated:NO completion: ^{
//obtain a pointer to the menu VC's view
UIView *menuTemp = appDelegate.menuVC.view;
//replace menu VC's view with the empty container view
appDelegate.menuVC.view = container;
//add the menu view to the container view and set its frame off screen
[container addSubview:menuTemp];
menuTemp.frame = CGRectMake(-260.0f, 0.0f, 260.0f, 548.0f);
//add the the view that was displayed when the user pressed the menu button. set its frame to fill the screen as normal
[appDelegate.menuVC.view addSubview:presenter];
presenter.frame = CGRectMake(0.0f, 0.0f, 320.0f, 548.0f);
//animate the 2 subviews that were just added; "PRESENTER"'S FRAME IS THE ISSUE
[UIView animateWithDuration:25.3f delay:0.0f options:nil animations:^{
[menuTemp setFrame:CGRectMake(0.0f, 0.0f, 260.0f, 548.0f)];
[presenter setFrame:CGRectMake(260.0f, -20.0/* or 0 */f, 320.0f, 548.0f)];
} completion:nil];
}];
}
これが私の2つのオプションの図です(クリックすると高解像度になります):
画面 1) 最初の画面は、メニュー ボタンをクリックする前のビューを示しています。
次の 2 つの画面では、メニュー遷移のアニメーションが始まるときに 2 つの可能性が示されます。
screen 2) presenter.frame.y.min を -20 に設定すると、トランジションは次のようになります。ご覧のとおり、ビュー内のボタンが 20 ピクセル飛び出しています。
画面 3) これは、presenter.frame.y.min を 0 に設定したときの遷移の様子です。ご覧のとおり、高さ 20 ピクセルのバーが上部に表示されます。青色はコンテナ ビューを示します。