我正在制作一个应用程序,它在单击时显示/隐藏(在自定义动画中) UINavigationBar。
我创建了两个功能(一个用于显示,另一个用于隐藏)。显示 UINavigationBar 的功能完美运行:
- (void) showNavigationBar {
[UINavigationBar beginAnimations:@"NavBarFadeIn" context:nil];
self.navigationController.navigationBar.alpha = 0;
[UINavigationBar setAnimationCurve:UIViewAnimationCurveEaseIn];
[UINavigationBar setAnimationDuration:0.5];
[UINavigationBar setAnimationTransition:UIViewAnimationOptionTransitionFlipFromTop
forView:self.navigationController.navigationBar
cache:YES];
self.navigationController.navigationBar.alpha = 1;
[UINavigationBar commitAnimations];
}
但是隐藏它的功能,即使它是相同的,也不起作用。UINavigationBar 突然消失,没有动画。
- (void) hideNavigationBar {
[UINavigationBar beginAnimations:@"NavBarFadeOut" context:nil];
self.navigationController.navigationBar.alpha = 1;
[UINavigationBar setAnimationCurve:UIViewAnimationCurveEaseIn];
[UINavigationBar setAnimationDuration:0.5];
[UINavigationBar setAnimationTransition:UIViewAnimationOptionTransitionCurlUp
forView:self.navigationController.navigationBar
cache:YES];
self.navigationController.navigationBar.alpha = 0;
[self.navigationController setNavigationBarHidden:YES animated:NO];
[UINavigationBar commitAnimations];
}
召唤:
- (void)contentView:(ReaderContentView *)contentView touchesBegan:(NSSet *)touches
{
if( [[self navigationController] isNavigationBarHidden] == NO)
{
if (touches.count == 1) // Single touches only
{
UITouch *touch = [touches anyObject]; // Touch info
CGPoint point = [touch locationInView:self.view]; // Touch location
CGRect areaRect = CGRectInset(self.view.bounds, TAP_AREA_SIZE, TAP_AREA_SIZE);
if (CGRectContainsPoint(areaRect, point) == false) return;
}
[mainToolbar hideToolbar];
[mainPagebar hidePagebar]; // Hide
[self hideNavigationBar];
lastHideTime = [NSDate new];
}
}
有人知道为什么会这样吗?