【问题标题】:toolbar hide behind the navigation image工具栏隐藏在导航图像后面
【发布时间】:2012-04-02 14:12:44
【问题描述】:
我正在创建一个必须使用导航图像的应用程序。
没有导航图像我可以完美地看到工具栏选项
应用启动主屏幕上没有图像的导航栏
导航到第二页后的导航图像
现在我正在使用
在导航栏中添加图像
UIImageView *topBar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 45)];
topBar.image = [UIImage imageNamed:@"top_cell.png"];
[self.navigationController.navigationBar addSubview:topBar];
现在导航栏看起来像主屏幕一样完美
但在第二页中工具栏选项隐藏了
那么如何在导航栏中的图像上方显示工具栏?
【问题讨论】:
标签:
objective-c
ios
xcode
ipad
【解决方案1】:
试试
[self.navigationController.navigationBar insertSubview:topBar belowSubview:navigationBar];
它将在您的导航栏下插入您的视图。
第二种选择是在您的代码之后使用此代码:
[self.navigationController.navigationBar bringSubviewToFront: topBar]
这会将您的顶部栏放在视图堆栈的顶部。
【解决方案2】:
最后我找到了解决方案,首先我在viewWillAppear 方法中添加了图像,然后在viewDidAppear 方法中添加了我的工具栏,就像下面的代码一样
-(void)viewWillAppear:(BOOL)animated
{
// self.navigationController.navigationBarHidden = TRUE;
///// Edit Hiren
UIImageView *topBar = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 45)];
topBar.image = [UIImage imageNamed:@"top-bar.png"];
[self.navigationController.navigationBar addSubview:topBar];
}
-(void)viewDidAppear:(BOOL)animated
{
toolbar.frame = CGRectMake(0, 0, 685, 44);
// [toolbar sizeToFit];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
// [self.navigationController.view addSubview:toolbar];
}