呈现模态视图控制器导航z位置问题

时间:2012-11-02 11:37:32

标签: ios uinavigationcontroller uinavigationbar presentmodalviewcontroller

我在rootview Controller上创建了导航栏

- (void)viewWillAppear:(BOOL)animated
{
    ///set hud
    [UIApplication sharedApplication].networkActivityIndicatorVisible=YES;
    [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:NO];
    //Set Apps navbar
    self.title=@"Trip Planer";

    UINavigationBar *navBar= self.navigationController.navigationBar;
    //[navBar setTintColor:[UIColor colorWithRed:0.102 green:0.498 blue:0.812 alpha:1] /*#1a7fcf*/];

    UIImage *imagebar = [UIImage imageNamed:@"Menu-Bar"];
    [navBar setBackgroundImage:imagebar forBarMetrics:UIBarMetricsDefault];

    ////set rightbutton menus
    UIButton *rightButton = [[UIButton alloc] init];
    rightButton.frame=CGRectMake(0,100.0f,23,23);
    [rightButton setBackgroundImage:[UIImage imageNamed: @"Filters"] forState:UIControlStateNormal];
    rightButton.highlighted=false;
    [rightButton addTarget:self action:@selector(showFilters:) forControlEvents:UIControlEventTouchDown];

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
    navBar.layer.zPosition=1;

    [rightButton release];
}

我使用TSMiniwebBrowser作为模态窗口

-(void) initTitleBar {
    UIBarButtonItem *buttonDone = [[UIBarButtonItem alloc] initWithTitle:modalDismissButtonTitle style:UIBarButtonItemStyleBordered target:self action:@selector(dismissController)];

    UINavigationItem *titleBar = [[UINavigationItem alloc] initWithTitle:@""];
    titleBar.leftBarButtonItem = buttonDone;


    CGFloat width = self.view.frame.size.width;
    UIImage *navbarPortrait = [[UIImage imageNamed:@"Menu-Bar"]
                               resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
    navigationBarModal = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, width, 44)];
    [[UINavigationBar appearance] setBackgroundImage:navbarPortrait
                                       forBarMetrics:UIBarMetricsDefault];
    navigationBarModal.layer.zPosition=700.0;
    NSLog(@"%f",navigationBarModal.layer.zPosition);
    //navigationBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin;
    navigationBarModal.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    [navigationBarModal pushNavigationItem:titleBar animated:NO];

    [self.view addSubview:navigationBarModal];
}

主要问题是rootviewcontroller上的导航栏总是覆盖 TSMiniWeb浏览器事件我改变TSminiBrowser Navbar的zposition比viewcontroller更大..我的代码有什么不对吗?

1 个答案:

答案 0 :(得分:0)

addSubview不是呈现模态视图控制器的正确方法。我建议你阅读适用于iOS的View Controller编程指南,特别是Presenting View Controllers from Other View Controllers