【问题标题】:UIToolbar doesn't show up after it's being hiddenUIToolbar 隐藏后不显示
【发布时间】:2012-05-27 13:38:12
【问题描述】:

我有一个 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");
        }
}

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

【问题讨论】:

    标签: objective-c uitoolbar


    【解决方案1】:

    当您为工具栏的显示设置动画时,您必须在 animations 块中将 alpha 设置为 1.0f

    下面是正确的代码;我已经用注释标记了我更改的行。

    - (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");
        }
    }
    

    【讨论】:

    • 非常感谢!工作! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    • 2011-02-27
    相关资源
    最近更新 更多