很多时候我们需要使用presentModalViewController来显示Modal View。如果需要显示半透明的Modal View应该怎么办呢?当然可以自己创建一个半透明的UIView,然后模拟presentModalViewController的动画效果。
不过iOS 4以后的版本再也不需要怎么麻烦了,有一个非常简单的方法,示例如下(这段代码运行于一个View Controller中):
UIViewController* transparentView = [[UIViewController alloc] init];
UIViewController* controller = self.view.window.rootViewController;
transparentView.view.backgroundColor = [UIColor clearColor];
controller.modalPresentationStyle = UIModalPresentationCurrentContext;
[controller presentModalViewController:transparentView animated:YES];其要点就是使用iOS特有的rootViewController来显示Modal View。
本文介绍了一种在iOS应用中使用UIViewController展示半透明ModalView的简便方法。通过设置特定属性,可以在不增加额外工作量的情况下实现所需效果。
1万+

被折叠的 条评论
为什么被折叠?



