简体   繁体   中英

iOS size of navigation bar back button

I am creating a taller navigation bar, height == 200, however, when i clicked below the back button, it also navigates back.

在此处输入图片说明

here is my code:

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

Any help will be appreciated

you can use custom button giving height as per your need

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

Apple Support:

I recommend that you avoid having touch-sensitive UI in such close proximity to the nav bar or toolbar. These areas are typically known as "slop factors" making it easier for users to perform touch events on buttons without the difficulty of performing precision touches. This is also the case for UIButtons for example.

But if you want to capture the touch event before the navigation bar or toolbar receives it, you can subclass UIWindow and override: -(void)sendEvent:(UIEvent *)event;

https://stackoverflow.com/a/9719364/2138564

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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