我现在正在我的应用程序中使用UINavigationController。我在此导航控件的视图中添加了一个按钮,以便此按钮显示在navigationBar的顶部。 问题是当我隐藏navigationBar并隐藏按钮并再次显示它们时,NavigationBar会出现在按钮的顶部。 任何人都可以解决这个问题吗?
@interface MyNavigationController : UINavigationController<UINavigationControllerDelegate>
{
UIButton *btnBack ;
}
-(id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
if (self)
{
self.delegate = self ;
self.navigationBar.barStyle = UIBarStyleBlack;
//btnBack
UIImageView *gameImage = [[UIImageView alloc] initWithFrame:CGRectMake(1, 1, 32, 27)];
self.btnBack = [UIButton buttonWithType:UIButtonTypeCustom];
self.btnBack.frame = CGRectMake(10, 5.0, 60, 30);
[self.btnBack setBackgroundImage:[UIImage imageNamed:@"backicon.png"] forState: UIControlStateNormal];
[self.btnBack addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
[self.btnBack addSubview: gameImage];
[self.view addSubview:self.btnBack];
}
return self ;
}
-(void)hideNavigationItems
{
[self setNavigationBarHidden:YES animated:YES];
self.btnBack.hidden = YES ;
}
-(void)showNavigationItems
{
self.navigationBarHidden = NO;
self.btnBack.hidden = NO ;
}
答案 0 :(得分:0)
如评论中所述,请尝试:
[self.view bringSubviewToFront:btnBack];