我有一个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");
}
}
问题在于,当我尝试隐藏工具栏时,它工作正常。但是,当我试图再次显示它时,它不会出现。 有任何想法吗?
答案 0 :(得分:1)
在为工具栏的显示设置动画时,您必须将1.0f
块中的alpha设置为animations
。
以下是正确的代码;我用评论标记了我改变的那一行。
- (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");
}
}