發(fā)現(xiàn)一個NB的東西,原來實現(xiàn)半透明效果就是添加一個半透明的View,但是如何才能模態(tài)出一個控制器呢,這種需求還是很常見的吧...
老方法一般都是創(chuàng)建一個自己的Window,然后添加新的控制器在Window上,設置window顏色,控制器顏色為clearColor,還是挺麻煩的,今兒扒扒撿撿,找到一個屬性可以達到這種效果
modalPresentationStyle
typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
UIModalPresentationFullScreen = 0,
UIModalPresentationPageSheet NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
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,
};
上面顯示的一樣,在原來只提供了4個屬性,后來又添加了之后的這些
UIModalPresentationFullScreen這個是默認的,充滿全屏
UIModalPresentationPageSheet這個是像sheet的效果,但是是滿屏的,如果橫屏的話才會出效果,就是一個豎屏的大小周邊都是不能點擊的灰色
UIModalPresentationFormSheet類似Sheet的效果
UIModalPresentationCurrentContext跟父類出現(xiàn)的樣式一樣
UIModalPresentationCustom自定義樣式
好了,說一下怎么創(chuàng)建一個透明的控制器覆蓋在老控制器上面
如果A present B設置 A.definesPresentationContext = YES; B.modalPresentationStyle = UIModalPresentationOverCurrentContext; B.view 是半透明的跺撼,然后讓A 把B present 出來霸褒,就是半透明的