2012-05-27 118 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