How to add UIView over navigation bar?

前端 未结 5 437
没有蜡笔的小新
没有蜡笔的小新 2021-02-02 15:38

I need overlay UINavigationBar with UIView like here

\"http://screencast.com/t/ZKXNFcAzVu

5条回答
  •  情歌与酒
    2021-02-02 15:42

    You can add a subview to the base view of the Application

    [[[UIApplication sharedApplication] keyWindow] addSubview:vMyCustomUIView];
    

    To make sure it is only shown when your view controller is visible you could add and remove it in the viewDidAppear and viewDidDisappear delegate methods. Here is an example that would show a blue box overlapping them.

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.    
        vTestView = [[UIView alloc] initWithFrame:CGRectMake(10.0f,
                                                             10.0f,
                                                            100.0f,
                                                            100.0f)];
        vTestView.backgroundColor = [UIColor blueColor];
    }
    
    
    -(void)viewDidAppear:(BOOL)animated
    {
        [[[UIApplication sharedApplication] keyWindow] addSubview:vMyCustomUIView];
    }
    -(void)viewDidDisappear:(BOOL)animated
    {
        [vMyCustomUIView removeFromSuperview];
    }
    

提交回复
热议问题