以下を使用して、一連のボタンをUINavigationBarに追加しています。
NSArray *items;
items = [NSArray arrayWithObjects:
fixedSpace,
refreshStopBarButtonItem,
flexibleSpace,
self.backBarButtonItem,
flexibleSpace,
self.forwardBarButtonItem,
flexibleSpace,
self.actionBarButtonItem,
fixedSpace,
nil];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, toolbarWidth, 44.0f)];
toolbar.items = items;
toolbar.tintColor = [[UIColor whiteColor] colorWithAlphaComponent:1.0];
toolbar.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
すべてうまく機能しています。
ただし、横向きモードに回転すると、uinavigationbar内のツールバーが回転しません。
このコード(SOにあります)を追加すると、ツールバーのサイズは変更されますが、その中のボタンは変更されないため、下部で部分的にトリミングされ、ツールバーの背景と一致しなくなります
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGRect navigationToolbarFrame = self.navigationController.navigationBar.frame;
CGRect customToolbarFrame = CGRectOffset(navigationToolbarFrame, 0.0, navigationToolbarFrame.size.height);
[UIView animateWithDuration:duration animations:^{
//self.toolbar.frame = customToolbarFrame;
// FAILS!!!
//self.navigationItem.rightBarButtonItem.toolbar.frame = customToolbarFrame;
// FAILS!!!
}];
}
uinavigationbar内のツールバーに対処する正しい方法は何ですか?何かのようなもの...
self.toolbar.frame = customToolbarFrame;
または、UIBarButtonItemsの自動サイズ変更マスクを指定する必要がありますか?...
self.backBarButtonItem.autoresizingMask = UIViewAutoresizingFlexibleHeight;
...このようにしようとすると失敗します