2012-05-27 86 views
0

我有一个UIButton,它使UIToolbar显示和隐藏。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"); 
     } 
} 

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

回答

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

非常感谢你!成功了! :) – Phillip