以透明背景和过渡样式从标签栏以模态方式打开UIViewController

时间:2014-11-18 15:32:20

标签: uiviewcontroller uinavigationcontroller modalviewcontroller presentviewcontroller

我已经使用此链接创建了自定义标签栏:https://github.com/jain-mohit/CustomTabBar。现在,我想按下按钮后以模态方式打开视图。打开的视图必须是透明的,这意味着我可以看到它下面的视图。模态视图也必须有一个导航栏,所以我可以放一个"取消"按钮解雇它。我试过这样的话:

DetailsViewController *detailViewController = [[DetailsViewController alloc] init];


UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:detailViewController];
nav.modalPresentationStyle = UIModalPresentationCurrentContext;

nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
detailViewController.view.backgroundColor = [UIColor greenColor];
detailViewController.view.alpha = 0.5f;

[self  presentViewController:nav animated:YES completion:nil];

此方法非常有效,但在打开时,视图不会从下到上过渡。而且我也遇到了这个错误:

Presenting view controllers on detached view controllers is discouraged <UINavigationController: 0x8f52280>

所以,我正在寻找另一种方法来做到这一点。希望有人可以提供帮助。此方法适用于iOS6,7和8.此外,我没有使用故事板来执行此操作。

谢谢。

1 个答案:

答案 0 :(得分:-2)

尝试使用UIWindow,而不是展示新的ViewController:

UIWindow *w = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
w.windowLevel = UIWindowLevelAlert;
w.autoresizesSubviews = NO;
w.clipsToBounds = YES;
w.hidden = NO;
[w addSubview:detailViewController];

在这种情况下,你的新ViewController的背景将是透明的,但你不能在这里使用UINavigationController ......