簡體   English   中英

如何將視圖添加到整個屏幕

[英]How to add the view to whole screen

我有一個2 vc,可以從一個屏幕推到另一個屏幕。在我的vc2中,我以編程方式添加了導航欄標題,bar button。 但是,當我添加視圖時,從頂部減少了10點。 沒有完全顯示。 我嘗試了所有可能性。 附加圖像:

在我的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];

}

在此處輸入圖片說明 但是請問您有什么想法嗎?

我正在使用@ Anbu.Karthic解決方案進行更新。

(IBAction)MenuTap:(id)sender使用以下代碼更新代碼。 它會工作。 我努力了。

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

根據此處的問題添加了詳細答案,如果要顯示在狀態欄下方,則需要首先獲取狀態欄的高度,然后在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