【发布时间】:2019-02-15 09:22:58
【问题描述】:
我有一个 2 vc,从一个屏幕推送到另一个屏幕。在我的 vc2 中,我以编程方式添加导航栏标题,栏按钮。但是当我添加视图时,从顶部减少了大约 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];
}
【问题讨论】:
-
你的问题不清楚。你提到的导航栏,橙色视图
-
橙色是我的看法。顶部是导航栏的正常视图。我需要展示我的橙色视图来咬。这样顶部的白色也不应该显示
-
添加框架
_menuView.frame = [[UIScreen mainScreen] bounds] -
使用哪个代码。我尝试了所有的可能性。我需要在哪一行添加这个?
-
是否可以附加您的项目
标签: ios objective-c xcode view navbar