0

我想知道是否有办法在说 if 语句合格时出现正确的导航栏按钮.. 所以说如果用户正在填写一些详细信息然后 if 语句运行有没有办法按钮从不存在变为淡入并可选择?

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

这就是我目前正在做的一切。

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

3 回答 3

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) {
                 }];
}

它应该有效!

于 2012-04-18T06:51:30.350 回答
1

使用 -initWithCustomView 在 UIBarbuttonItem 内创建一个 UIButton,该 UIBarbuttonItem 又位于导航栏内,PHEW!然后你就可以完全访问 alpha 的 UIButton,一个奢侈的 UIBarButtonItem 是买不起的。

当然,这都是 iOS 5 之前的内容。使用 +appearance 将视图的 backgroundColor 从 0.0 alpha 设置为 1.0 alpha(注意,在这种情况下 UIColor 不可设置动画,请使用 CGColor 属性)。

于 2012-04-18T05:07:17.630 回答
1

在某种程度上实现这一点的一种简单方法是修改您的按钮setEnable状态。这不会改变按钮是否可见,但会切换用户是否可以与之交互,就像这样。

在此处输入图像描述

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

}else {
    [myBarButtonItem setEnabled:YES];
}
于 2012-04-18T05:36:19.090 回答