简体   繁体   English

如何将视图添加到整个屏幕

[英]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 . 我有一个2 vc,可以从一个屏幕推到另一个屏幕。在我的vc2中,我以编程方式添加了导航栏标题,bar button。 But when i add the view some 10 points from top is reduced. 但是,当我添加视图时,从顶部减少了10点。 not showing fully. 没有完全显示。 I tried all the possibilities. 我尝试了所有可能性。 Attached the image also: 附加图像:

in my vc2 : 在我的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. 我正在使用@ Anbu.Karthic解决方案进行更新。

In your (IBAction)MenuTap:(id)sender update the code with below. (IBAction)MenuTap:(id)sender使用以下代码更新代码。 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. 根据此处的问题添加了详细答案,如果要显示在状态栏下方,则需要首先获取状态栏的高度,然后在y位置添加所需的位置。

 - (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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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