目标C语言 正确的方式转换视图,使导航/标签栏动画好看



在我的应用程序中,我有不同颜色的导航栏。还有,我有一些图形是横向显示的,而我应用的其他部分是纵向显示的。在某些视图中,我隐藏了标签栏。

我改变了viewDidLoad和viewWillAppear中导航条的颜色。

我的问题是视图之间的过渡效果看起来很奇怪。如果导航栏的颜色不同,那么颜色变化太快,第一个屏幕就会发生变化。或者你可以看到标签栏被移除。

我做错了什么?

下面是我使用的一些典型代码:

CBViewController *nextController = [[CBViewController alloc] 
      initWithNibName:@"CBView" bundle:nil];
nextController.title = @"CB";   
nextController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:nextController animated:YES];

我不是在寻找没有标准的效果,而是一些看起来不奇怪的东西。

虽然,我已经看到了滑动的效果,从第一个视图到第二个看起来不错。

在你的评论之后,我仍然不确定你在寻找什么-我没有看到任何导航栏的颜色改变在我的iTunes(他们更新iTunes如此频繁,也许我们看到的是不同的版本)。无论如何,下面的代码将导致导航栏在过渡到新控制器时改变颜色。由于推送动画只有大约0.3秒,而NSTimer的分辨率限制在大约0.05秒,所以我在从一种颜色到下一种颜色(从绿色到黄色)的转换过程中执行了六个步骤。

-(IBAction)pushWithColorChange:(id)sender {
    UIViewController *nextController = [self.storyboard instantiateViewControllerWithIdentifier:@"Yellow"];
    [self.navigationController pushViewController:nextController animated:YES];
    [NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:@selector(changeColor:) userInfo:nil repeats:YES];
}
-(void)changeColor:(NSTimer *) timer {
    static float i=0.03;
    self.navigationController.navigationBar.tintColor = [UIColor colorWithHue:.34 - i saturation:.5 brightness:.7 alpha:1];
    i += 0.03;
    if (i > .18) {
        [timer invalidate];
    }
}

最新更新