Issue with button on the left side of the uinavigation bar

后端 未结 3 621
野的像风
野的像风 2021-01-03 11:32

I have a button on the left side of the navigation bar. I also have a UIButton near that button.

Now when I click the button thats below the navigation bar, in many

相关标签:
3条回答
  • 2021-01-03 12:01

    UINavigationButtons have a much larger tappable area than it's view, Apple made it this way for ease of use. If you really want to have two buttons that close to each other you have to subclass UINavigationBar, more specifically, override the touch events, get the touch coordinates and act as you see fit. More info here.

    0 讨论(0)
  • 2021-01-03 12:13

    It looks like a problem with how you're initializing the UIButton instance. Typically, we would use [UIButton buttonWithType:custom]; in your situation.

    From this answer, they solved a similar question with the following:

    UIImage *myImage = [UIImage imageNamed:@"paw.png"];
    UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [myButton setImage:myImage forState:UIControlStateNormal];
    myButton.showsTouchWhenHighlighted = YES;
    myButton.frame = CGRectMake(0.0, 0.0, myImage.size.width, myImage.size.height);
    
    [myButton addTarget:self action:@selector(tapped:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:myButton];
    self.navigationItem.rightBarButtonItem = rightButton;
    
    [rightButton release];
    [myButton release];
    

    It's not the code you're looking for, but it shows you how to correctly instantiate a UIButton instance. Hopefully that will sort out the problems you're having.

    0 讨论(0)
  • 2021-01-03 12:15

    Note that if Apple enlarged the navigationBar's left button (right one is not), it's for usability questions. It's almost the most clicked button of iphone device, so people have got the ability to tap back button in an instinctive way (i never look at the button, I just know the movement).

    Have in mind that if you reduce the touch region, users may have difficulties to reach it.

    My recommandation, sorry for that, would be to move down 3 or 5px down your 3 buttons.

    0 讨论(0)
提交回复
热议问题