简体   繁体   中英

How to add the view to whole screen

I have an 2 vc,with push from one screen to another screen.In my vc2 programmatically i am adding the nav bar title, bar button . But when i add the view some 10 points from top is reduced. not showing fully. I tried all the possibilities. Attached the image also:

in my vc2 :

- (void)viewDidLoad {
    [super viewDidLoad];
    _menuView.hidden = YES;
    [self navItems];
}

    -(void)navItems{

        UIImage* filterImage = [UIImage imageNamed:@"filter.png"];
        CGRect frameimg = CGRectMake(0,0, 15,15);

        filterBtn = [[UIButton alloc] initWithFrame:frameimg];
        [filterBtn setBackgroundImage:filterImage forState:UIControlStateNormal];

        [filterBtn addTarget:self action:@selector(MenuTap:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *filter =[[UIBarButtonItem alloc] initWithCustomView:filterBtn];
        self.navigationItem.rightBarButtonItem = filter;

        self.title = @"Demo";
         self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    }
- (IBAction)MenuTap:(id)sender
{


     _menuView.hidden = NO;

//1
//   [self.navigationController.view addSubview:_menuView];
//    [self.view addSubview:_menuView];

    //2
//    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
//    [window addSubview: _menuView];
//

//3
   // UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow;
    //[currentWindow addSubview:_menuView];


//4
  //[[UIApplication sharedApplication].windows.lastObject addSubview:_menuView];

//5
   // self.navigationController.navigationBar.layer.zPosition = -1;
    //[self.view addSubview:_menuView];

}

在此处输入图片说明 But not able to show fully any idea please ?

I am updating with @Anbu.Karthic solution.

In your (IBAction)MenuTap:(id)sender update the code with below. It will work. I have tried.

- (IBAction)MenuTap:(id)sender
{
  _menuView.hidden = NO;
 [self.navigationController.view addSubview:_menuView];
  _menuView.frame = [[UIScreen mainScreen] bounds];
}

based on your question in here added the detail answer, if you want to show below the status bar , then you need to get the status bar height initially, there after you need to add the y position how much you need.

 - (IBAction)MenuTap:(id)sender
{
  _menuView.hidden = NO;
  //initially getStatusbar height
  float statusBarHeight = [self statusBarHeight];
  // assign your subview to window bounds
  _menuView.frame = [[UIScreen mainScreen] bounds];
  CGRect frameRect = _menuView.frame;
  // convert your y- coordinates based on your need
  frameRect.origin.y = statusBarHeight;
 _menuView.frame = frameRect;
 [self.navigationController.view addSubview:_menuView];

}



-(float) statusBarHeight
{
    CGSize statusBarSize = [[UIApplication sharedApplication] statusBarFrame].size;
    return MIN(statusBarSize.width, statusBarSize.height);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM