在更改alpha后,UIToolbar中的UIButton没有响应

时间:2014-05-31 07:43:29

标签: ios uibutton

我有一个使用故事板创建的项目。我有UIToolbar,其中UIToolarItemUIButton

当用户点击屏幕时,它会触发一个操作,该动作将为UIButton

的alpha值设置动画

如下所示:(这是调用按钮的alpha变化的方法

- (IBAction)tapDetected:(UIGestureRecognizer *)sender {
    NSLog(@"tapped: %f", self.mainViewToolbar.alpha);
    NSLog(@"%s", __PRETTY_FUNCTION__);


    if (self.buttonCall.alpha > 0.0) {
        [UIView animateWithDuration:1.0 animations:^(void) {
            self.buttonCall.alpha = 0.0;
        }];
    }
    else //(self.buttonEmergencyCall.alpha < 1.0)
    {
        [UIView animateWithDuration:1.0
                              delay: 0.0
                            options: UIViewAnimationOptionTransitionFlipFromLeft
                         animations:^{
                             self.buttonCall.alpha = 1.0;
                         }
                         completion:nil];

        [UIView animateWithDuration:1.0
                              delay: 5.0
                            options: UIViewAnimationOptionTransitionFlipFromLeft
                         animations:^{
                             self.buttonCall.alpha = 0.0;
                         }
                         completion:nil];
    }


    if (sender.view == self.toolbarForMainScreen) {
        NSLog(@"clicking on the toolbar");
    }

}

按钮响应点击直到上面的代码运行,然后它停止响应用户点击。

有什么想法吗?

3 个答案:

答案 0 :(得分:1)

你设置alpha为0,你的控制器将被隐藏。你必须设置最小alpha为0.1才能获得它的其他按钮将隐藏。看到这个我用demo演示,我在Method:

中点击了一下设置IBAction
 float alf = 1.0;
- (IBAction)addSubview:(id)sender
{
    [self.btnAdd setAlpha:alf];

    alf-=0.1;
    NSLog(@"Tapp working");

}

并且按钮i的每次单击从alpha 1减少0.1并且调用方法直到该按钮alpha为0.1然后不调用。所以这意味着当你设置alpha为0时控制器将被隐藏。 在列表中,您必须设置最小控制Alpha为0.1

enter image description here

答案 1 :(得分:0)

请参阅,如果任何其他视图与UI按钮重叠,则

答案 2 :(得分:0)

最佳做法:尝试使用像这样的完成块

[UIView animateWithDuration:1.0 animations:^{

    self.buttonCall.alpha = 1.0;        

} completion:^(BOOL finished) {

    [UIView animateWithDuration:1.0 animations:^{

        self.buttonCall.alpha = 0.0;

    } completion:^(BOOL finished) {


    }];
}];