幾種modalPresentationStyle解析

經過設置presenting VC的modalPresentationStyle屬性,咱們能夠設置彈出View Controller時的風格,有如下四種風格,其定義以下:spa

typedef enum {
    UIModalPresentationFullScreen = 0,
    UIModalPresentationPageSheet,
    UIModalPresentationFormSheet,
    UIModalPresentationCurrentContext,
} UIModalPresentationStyle;

  UIModalPresentationFullScreen表明彈出VC時,presented VC充滿全屏,若是彈出VC的wantsFullScreenLayout設置爲YES的,則會填充到狀態欄下邊,不然不會填充到狀態欄之下。code

  UIModalPresentationPageSheet表明彈出是彈出VC時,presented VC的高度和當前屏幕高度相同,寬度和豎屏模式下屏幕寬度相同,剩餘未覆蓋區域將會變暗並阻止用戶點擊,這種彈出模式下,豎屏時跟UIModalPresentationFullScreen的效果同樣,橫屏時候兩邊則會留下變暗的區域。orm

  UIModalPresentationFormSheet這種模式下,presented VC的高度和寬度均會小於屏幕尺寸,presented VC居中顯示,四周留下變暗區域。it

  UIModalPresentationCurrentContext這種模式下,presented VC的彈出方式和presenting VC的父VC的方式相同。io

  這四種方式在iPad上面通通有效,但在iPhone和iPod touch上面系統始終已UIModalPresentationFullScreen模式顯示presented VC。方法

使用方法爲:im

// 例:在類ControllerA中彈出類ControllerB UITableViewControllermargin

// 在類ControllerA對應的方法中實現touch

ControllerB *cb = [[[ControllerB alloc] initWithNibName:nil bundle:nil] autorelease];top

cb.modalPresentationStyle = UIModalPresentationFormSheet;

[self presentModalViewController:cb animated:YES];

相關文章
相關標籤/搜索