简体   繁体   中英

UINavigationController Back Button Chevron in iOS 7

I would love to say that I'm enjoying this transition to iOS 7, but it feels like battle after battle to just get the app functional again.

My current issue is with a uinavigationcontroller. It's embedded in a tab controller. The problem occurs when the user starts drilling down into categories. The back button chevron moves to the upper left portion of the navigation bar while the actual back button remains fixed in its normal spot. The code isn't doing any manipulation. It's just pushing and popping view controllers.

Here's a screenshot of the issue:

在此处输入图片说明

Has anyone encountered this problem and have any ideas how I may fix it? All suggestions are welcome.

Have you changed the font size - this may have changed the line-height value causing displacement?

It maybe best to opt for a custom back button so you have more control of the placement. You can place this snippet in viewDidLoad

if ( [self.navigationController.viewControllers count] > 1 )
{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setAdjustsImageWhenHighlighted:NO];
    [backBtn setShowsTouchWhenHighlighted:YES];
    [backBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
    UIImage *backBtnImage = [UIImage imageNamed:@"back.png"]; // <-- Use your own image
    [backBtn setImage:backBtnImage forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
    backBtn.frame = CGRectMake(0, 0, 40, 40);
    UIBarButtonItem *backBarBtnItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backBarBtnItem;
}

Also add the method for custom back button touch event:

- (void)goBack
{
    [self.navigationController popViewControllerAnimated:YES];
}

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