[英]iOS 7 UINavigationController transition to UITableView: black-translucent layer during animation
in my new iOS app I'd like to use a fixed background for the entire app and its views. 在我的新iOS应用中,我想为整个应用及其视图使用固定的背景。
When clicking the navigation item to show up the settings table controller an ugly black-translucent layer or something like this appears in a fraction of a second on the whole screen until the animation is done. 当单击导航项以显示设置表控制器时,丑陋的黑色半透明层或类似的东西在整个屏幕上的显示时间不到一秒钟,直到完成动画为止。
Any idea to remove this undesired behaviour? 是否有消除这种不良行为的想法? Thank you!
谢谢!
Demo: 演示:
better .mp4 version of the demo @ Dropbox 更好的.mp4版本的演示@ Dropbox
edit: The UINavigationController contains the background image. 编辑: UINavigationController包含背景图像。
My Settings TableViewController was modified like this: 我的设置TableViewController修改如下:
self.tableView.backgroundView = nil;
self.tableView.opaque = NO;
self.tableView.backgroundColor = [UIColor clearColor];
It's because of the standard UINavigationController
push animation in iOS 7. When a new ViewController is pushed onto the stack, it overlays itself on top of the previous ViewController, with a slight shadow underneath it. 这是因为iOS 7中使用了标准的
UINavigationController
推送动画。将新的ViewController推送到堆栈上时,它将自身覆盖在以前的ViewController的顶部,并在其下方有一个阴影。
The solution I think is to implement your own transition. 我认为解决方案是实施您自己的过渡。 Like this:
像这样:
Create a new UINavigationController
class, I name it CustomNavigationController
创建一个新的
UINavigationController
类,我将其命名为CustomNavigationController
CustomNavigationController.h CustomNavigationController.h
@interface UINavigationController (Retro)
- (void)pushViewControllerCustom:(UIViewController *)viewController;
@end
CustomNavigationController.m 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
To use it: 要使用它:
- (IBAction)barButtonItemPressed:(id)sender
{
TableViewController *tableView = [self.storyboard instantiateViewControllerWithIdentifier:@"table"];
[self.navigationController pushViewControllerCustom:tableView];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.