我想使用
的后导航动画[self.navigationController popViewControllerAnimated:YES]
在导航栏中添加了自定义按钮。
因为我不希望看到后退按钮,所以我用self.navigationItem.hidesBackButton = YES;
但是在后面的动画中,在ios7(不是ios6)上可以看到3个点在导航栏中滑动。
它们不会出现在self.navigationItem.hidesBackButton = NO;
中,但当然可以看到按钮。
有没有人有任何想法让它们不出现?
答案 0 :(得分:9)
如果您设置
self.navigationItem.hidesBackButton = YES
iOS有时会在其通用后退按钮中生成三个点。 我通过将通用后退按钮上的文本设置为空来解决了问题,然后创建了我的自定义按钮。这就是我设置空文本的方式:
UIBarButtonItem *backButton2 = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton2;
然后我创建了我的自定义UIButton并将其放置在我想要的位置:
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 70/2-22, 44, 44)];
[backButton setImage:[[UIImage imageNamed:@"back_button.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
backButton.tintColor = tintColor;
backButton.imageEdgeInsets = UIEdgeInsetsMake(-2, -15, 0, 0);
[backButton addTarget:self action:@selector(popCurrentViewController) forControlEvents:UIControlEventTouchUpInside];
答案 1 :(得分:2)
无需隐藏backButton
,您只需添加自定义后退按钮,它就会隐藏默认按钮。
- (void) viewDidLoad
{
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(handleBack:)];
self.navigationItem.leftBarButtonItem = backButton;
}
- (void) handleBack:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
答案 2 :(得分:2)
只需在viewWillAppear方法中添加以下这些行:
夫特:
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
目标C:
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
这就是全部
答案 3 :(得分:1)
navigationItem.backBarButtonItem = nil
答案 4 :(得分:0)
更简单的快速版本:
let emptyBackButton = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
navigationItem.hidesBackButton = true
navigationItem.backBarButtonItem = emptyBackButton
答案 5 :(得分:0)