我正在使用自定义 UIBarButtonItem 来替换 leftBarButtonItem,但是当我在按钮外部按下时,在按钮的大约 20 像素内,它会将其检测为按下的按钮。
这是我的代码:
- (void)changeNavbarButtons
{
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
[backButton setBackgroundImage:[UIImage imageNamed:@"navbarBack.png"] forState:UIControlStateNormal];
[backButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -5;
self.navigationItem.leftBarButtonItems = [NSArray
arrayWithObjects:negativeSpacer, backItem, nil]; self.navigationItem.hidesBackButton = YES;
}
negativeSpacer 是将按钮向左移动 5 个像素。
什么会导致这种情况?