1

我现在在我的应用程序中使用 UINavigationController 。我在这个 navigationcontroller 的视图中添加了一个按钮,这样这个按钮就会出现在 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 ;
}
4

1 回答 1

0

正如评论中所说,尝试:

[self.view bringSubviewToFront:btnBack];
于 2012-11-28T10:39:35.223 回答