动画导航栏按钮

时间:2012-04-18 05:04:21

标签: iphone ios xcode uinavigationbar

我想知道是否有一种方法可以使权利,导航栏按钮出现时说if语句是合格的..所以说如果用户填写一些细节然后if if statment运行是有一个使按钮从不在那里变为淡入和可选择的方式?

目前我只是把它放在那里,但是用户奖励很好,表明用户已经满足按下搜索按钮等的需要。

目前这就是我正在做的事情。

if (blaa blaa) {
//Add search barbutton
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Search" style:UIBarButtonSystemItemDone target:nil action:nil];
}

3 个答案:

答案 0 :(得分:2)

首先,您应该将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) {
                 }];
}

它应该有效!

答案 1 :(得分:1)

使用-initWithCustomView在UIBarbuttonItem中创建一个UIButton,而UIBarbuttonItem又位于导航栏内,PHEW!然后你就可以完全访问UIButton的alpha版本,这是UIBarButtonItem无法承受的奢侈品。

当然,这都是iOS 5 mumbo jumbo之前的版本。使用+外观为视图的backgroundColor设置动画,从0.0 alpha到1.0 alpha(注意,在这种情况下,UIColor不具有动画效果,请使用CGColor属性)。

答案 2 :(得分:1)

一种简单的方法可以修改按钮setEnable状态。这不会改变,按钮是可见的,但会切换用户可以与之交互,就像这样。

enter image description here

if (blahblah == YES) {
    [myBarButtonItem setEnabled:NO];

}else {
    [myBarButtonItem setEnabled:YES];
}