0

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];

}

enter image description here But not able to show fully any idea please ?

david
  • 636
  • 2
  • 12
  • 29
  • your question is not clear.you mentioned as nav bar , orange view – Anbu.Karthik Feb 15 '19 at 09:32
  • that orange is my view. And the top is my normal view with nav bar . I needs to show my orange view to bit up . So that that top white also should not show – david Feb 15 '19 at 09:35
  • add the frame `_menuView.frame = [[UIScreen mainScreen] bounds]` – Anbu.Karthik Feb 15 '19 at 09:40
  • With which code. I tried all the possibilities. With which line i needs to add this? – david Feb 15 '19 at 09:42
  • is this possible to attach your project – Anbu.Karthik Feb 15 '19 at 09:46
  • your image is not clear , add one clear image to understand the UI issue !! – vivekDas Feb 15 '19 at 09:49
  • If you are asking for top status bar then just set the status bar hidden true using the API setStatusBarHidden – vivekDas Feb 15 '19 at 09:51
  • @Anbu.Karthik its an big module. So not able to uplaod here. The thing is , i need to show the view till the status bar. But when i try all my post code the view is showing till the navigation bar half. But i need to hide the navigation bar and till my status bar – david Feb 15 '19 at 09:57

2 Answers2

1

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];
}
spike04
  • 126
  • 2
1

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);
}
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143