【问题标题】:iOS 7 UINavigationController transition to UITableView: black-translucent layer during animationiOS 7 UINavigationController 过渡到 UITableView:动画期间的黑色半透明层
【发布时间】: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];
【问题讨论】:
标签:
ios
objective-c
uitableview
uinavigationcontroller
uiviewanimationtransition
【解决方案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];
}