UIToolbar 隐藏后不显示
Posted
技术标签:
【中文标题】UIToolbar 隐藏后不显示【英文标题】:UIToolbar doesn't show up after it's being hidden 【发布时间】: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");
问题是当我尝试隐藏工具栏时,它工作正常。但是当我再次尝试显示它时,它不会出现。 有任何想法吗?
【问题讨论】:
【参考方案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");
【讨论】:
非常感谢!工作! :)以上是关于UIToolbar 隐藏后不显示的主要内容,如果未能解决你的问题,请参考以下文章