从具有透明背景和过渡样式的选项卡栏以模式方式打开UIView控制器



我有一个自定义标签栏,我使用此链接创建: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。我也没有使用故事板来做到这一点。

谢谢。

尝试使用 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];

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

最新更新