3

我有一个ViewController带有 aNavigationController并且我想在按下 ViewController 按钮时添加一个UIView带有一些按钮的半透明ViewController,问题是我无法UIViewNavigationBar. 我该如何解决这个问题?

这是我的代码(非常简单)

-(void)setOpacityView
{
    opacityVw = [[UIView alloc] initWithFrame:self.view.bounds];
    opacityVw.backgroundColor = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];


    WPCustomButton *closeBtn = [[WPCustomButton alloc] initWithFrame:CGRectMake(230, 10, 80, 20)];
    [closeBtn setTitle:@"Close X" forState:UIControlStateNormal];
    [closeBtn setBackgroundColor:[UIColor clearColor]];
    [closeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closeView) forControlEvents:UIControlEventTouchUpInside];
    [opacityVw addSubview:closeBtn];
}

// ---------------------------------------------------------------------------------------------------------------------

#pragma mark - Button methods

-(void) closeView
{
    [opacityVw removeFromSuperview];
}


-(void)setProfileImage
{
    [self setOpacityView];

    [self.view addSubview:opacityVw];
}
4

4 回答 4

4

我在这里回答了一个类似的问题

尝试这样的事情:

-(void)setProfileImage
{
    [self setOpacityView];
    [self.navigationController.view addSubview:opacityVw];
}
于 2013-10-31T16:55:34.720 回答
2

而是将其添加到 AppDelegate 中UIWindow

- (void)setProfileImage
{
    [self setOpacityView];

    [ [[UIApplication sharedApplication] delegate].window addSubview:opacityVw];
}

不要忘记更改视图大小:

opacityVw = [[UIView alloc] initWithFrame:[[[UIApplication sharedApplication] delegate]window].bounds];
于 2013-10-31T16:31:30.070 回答
0

您可以创建 MainViewController 并将其作为您的 window.rootViewController。将您的 navigationController 添加到此 MainViewController。之后,您将视图添加到您的 mainViewController,它将位于导航控制器的顶部。

于 2013-10-31T16:58:48.987 回答
0

简单点:

-(void)setProfileImage
{
    [self setOpacityView];
    self.navigationController.navigationBarHidden = YES;
    [self.view insertSubview:opacityVw aboveSubview:self.view];
}

-(void) closeView
{
    [opacityVw removeFromSuperview];
    self.navigationController.navigationBarHidden = NO;
}
于 2013-10-31T16:46:16.407 回答