-1

我有一个 UIButton,它使 UIToolbar 显示和隐藏。

- (IBAction)showHideToolbar:(id)sender{
    if (toolBar.hidden == NO) {
        [UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction animations:^(void){toolBar.alpha =0.0f;}completion:^(BOOL finished){
            toolBar.hidden = YES;}];
        NSLog(@"hides");
    }
    else
        if (toolBar.hidden == YES) {
            [UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^(void){toolBar.alpha =0.0f;}completion:^(BOOL finished){
                toolBar.hidden = NO;
            }];
            NSLog(@"show");
        }
}

问题是当我尝试隐藏工具栏时,它工作正常。但是当我再次尝试显示它时,它不会出现。有任何想法吗?

4

1 回答 1

1

当您为工具栏的显示设置动画时,您必须1.0fanimations块中设置 alpha。

以下是正确的代码;我已经用评论标记了我更改的行。

- (IBAction)showHideToolbar:(id)sender {
    if (toolBar.hidden == NO) {
        [UIView animateWithDuration:0.25f 
                              delay:0.0f 
                            options:UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction 
                         animations:^(void){ toolBar.alpha = 0.0f; }
                         completion:^(BOOL finished){ toolBar.hidden = YES; }];
        NSLog(@"hides");
}
else
    if (toolBar.hidden == YES) {
        [UIView animateWithDuration:0.25f 
                              delay:0.0f
                            options:UIViewAnimationCurveEaseIn | UIViewAnimationOptionAllowUserInteraction 
                         animations:^(void){ toolBar.alpha = 1.0f; } // Change from 0.0f to 1.0f
                         completion:^(BOOL finished){ toolBar.hidden = NO; }];
        NSLog(@"show");
    }
}
于 2012-05-27T13:50:56.920 回答