iOS 7 UINavigationController 过渡到 UITableView:动画期间的黑色半透明层

Posted

技术标签:

【中文标题】iOS 7 UINavigationController 过渡到 UITableView:动画期间的黑色半透明层【英文标题】:iOS 7 UINavigationController transition to UITableView: black-translucent layer during animation 【发布时间】:2014-08-24 21:55:30 【问题描述】:

在我的新 ios 应用中,我想为整个应用及其视图使用固定背景。

当单击导航项以显示设置表控制器时,一个难看的黑色半透明层或类似的东西会在几分之一秒内出现在整个屏幕上,直到动画完成。

有什么想法可以消除这种不良行为吗? 谢谢!

演示:

better .mp4 version of the demo @ Dropbox

编辑: UINavigationController 包含背景图像。

我的设置 TableViewController 修改如下:

self.tableView.backgroundView = nil;
self.tableView.opaque = NO;
self.tableView.backgroundColor = [UIColor clearColor];

【问题讨论】:

【参考方案1】:

这是因为 iOS 7 中的标准 UINavigationController 推送动画。当一个新的 ViewController 被推送到堆栈上时,它会覆盖在之前的 ViewController 之上,并在其下方有一个轻微的阴影。

我认为的解决方案是实现您自己的过渡。像这样:

新建一个UINavigationController类,我把它命名为CustomNavigationController

CustomNavigationController.h

@interface UINavigationController (Retro)

- (void)pushViewControllerCustom:(UIViewController *)viewController;

@end

CustomNavigationController.m

@implementation UINavigationController (Retro)

- (void)pushViewControllerCustom:(UIViewController *)viewController 
    CATransition *transition = [CATransition animation];
    transition.duration = 0.2;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
    //Fade here look nice, no more black shadow stuff
    transition.type = kCATransitionFade;
    transition.subtype = kCATransitionFromRight;
    [self.view.layer addAnimation:transition forKey:nil];

    [self pushViewController:viewController animated:NO];


@end

使用它:

- (IBAction)barButtonItemPressed:(id)sender

    TableViewController *tableView = [self.storyboard instantiateViewControllerWithIdentifier:@"table"];
    [self.navigationController pushViewControllerCustom:tableView];

【讨论】:

谢谢,这是一个不错的解决方案 :-)

以上是关于iOS 7 UINavigationController 过渡到 UITableView:动画期间的黑色半透明层的主要内容,如果未能解决你的问题,请参考以下文章

功能差异,UINavigationController vs Only Storyboard Segue

在 UINavigationController 中设置自定义导航栏类

在 UINavigationController 中设置自定义导航栏类

在 Swift 2.0 中设置 UINavigationController 栏标题

UINavigationController -> UIViewController -> UIView -> UITableViewController?

用动画隐藏导航控制器和标签栏控制器