我正在创建一个更高的导航栏,高度== 200,但是,当我点击后退按钮下方时,它也会导航回来。
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
navBar = [[SRNavigationBar alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 200.0)];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:NO];
[self.navigationItem setHidesBackButton:YES animated:YES];
__weak id weakSelf = self;
self.navigationController.interactivePopGestureRecognizer.delegate = weakSelf;
[self styleNavBar];
}
- (void)styleNavBar
{
UINavigationItem *newItem = [[UINavigationItem alloc]initWithTitle:[[PFUser currentUser] objectForKey:@"nickName"]];
UIBarButtonItem *menu = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStyleDone target:self action:@selector(back)];
newItem.leftBarButtonItem = menu;
newItem.leftBarButtonItem.tintColor = [UIColor colorWithRed:245/255.0 green:124/255.0 blue:0/255.0 alpha:1];
[navBar setItems:@[newItem]];
[self.view addSubview:navBar];
}
- (void)back
{
[self.navigationController popViewControllerAnimated:YES];
}
任何帮助将不胜感激
答案 0 :(得分:0)
您可以根据需要使用自定义按钮提供高度
-(void)addLeftButton
{
UIImage *buttonImage = [UIImage imageNamed:@"btn_back.png"];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
[aButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
aButton.frame = CGRectMake(0.0, 0.0, buttonImage.size.width, 200.0);
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];
[aButton addTarget:self action:nil forControlEvents:UIControlEventTouchUpInside];
[self.navigationItem setLeftBarButtonItem:aBarButtonItem];
}
答案 1 :(得分:0)
Apple支持:
我建议您避免使用触控式UI 靠近导航栏或工具栏。这些区域通常是已知的 作为“slop因素”,使用户更容易执行触摸事件 在按钮上没有执行精确触摸的困难。 例如,对于UIButton也是如此。
但是如果你想在导航栏之前捕捉触摸事件 或工具栏接收它,您可以子类化UIWindow并覆盖: - (void)sendEvent:(UIEvent *)event;