首先,您应该将 rightBarButtonItem 添加到导航栏并将 alpha 设置为 0.0
他们试试这个
[UIView animateWithDuration:0.3f
delay:0
options:UIViewAnimationCurveEaseInOut
animations:^{
self.navigationItem.rightBarButtonItem.customView.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
更新
在你的代码中
if (blaa blaa) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setTitle:@"search" forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView: btn] autorelease];
self.navigationItem.rightBarButtonItem.customView.alpha = 0.0f;
}
那么你可以使用上面的代码
更新
抱歉,我检查了代码,UIViewControler 将重置 barButtonItem 属性,因此您必须在视图显示之前设置为 agian
- (void)viewDidAppear:(BOOL)animated
{
self.navigationItem.rightBarButtonItem.customView.alpha = 0.0f;
}
然后当按钮被点击时
- (void) buttonTap:(UIButton*)btn
{
[UIView animateWithDuration:1.0f
delay:0
options:UIViewAnimationCurveEaseInOut
animations:^{
self.navigationItem.rightBarButtonItem.customView.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
它应该有效!