A -> B (A,B 均为 UIViewController 的实例,"->" 表示为模态的弹出一个视图控制器)
当弹出视图B,要求其背景为透明时,应设置一下属性,就可以实现背景透明。
//把A设置为当前控制器的背景。
A.definesPresentationContext = YES;
B.modalPresentationStyle = UIModalPresentationOverCurrentContext;
B.view.backgroundColor = [UIColor clearColor];
modalPresentationStyle
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
//是默认的,充满全屏,背景不透明。
UIModalPresentationFullScreen = 0,
//如果竖屏是满屏的;如果横屏就是竖屏的大小周边都是不能点击的灰色,背景不透明。
UIModalPresentationPageSheet NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
//类似Sheet的效果,背景不透明。
UIModalPresentationFormSheet NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
//与父类出现的样式一样,背景不透明。
UIModalPresentationCurrentContext NS_ENUM_AVAILABLE_IOS(3_2),
//自定义样式,背景可以透明。
UIModalPresentationCustom NS_ENUM_AVAILABLE_IOS(7_0),
//充满全屏,背景可以透明。
UIModalPresentationOverFullScreen NS_ENUM_AVAILABLE_IOS(8_0),
//与父类出现的样式一样,背景可以透明。
UIModalPresentationOverCurrentContext NS_ENUM_AVAILABLE_IOS(8_0),
//充满全屏,背景不透明。
UIModalPresentationPopover NS_ENUM_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED,
//无样式。
UIModalPresentationNone NS_ENUM_AVAILABLE_IOS(7_0) = -1,
};