2011-10-13 38 views
0

我一直在試圖理解爲什麼我的模態呈現的圖像沒有顯示在透明狀態欄底​​下。 _window.rootViewController是UILayoutContainerView,是在故事板中定義的第一個Responder視圖的Tab視圖的一部分。UIImageView意外調整大小模式使用presentViewController呈現

當presentViewController消息發送到RootViewController的,我可以在調用堆棧看到

UIWindowController過渡:fromViewController:toViewController:目標:didEndSelector:

叫我coverImageViewController與0,20,320,460的SETFRAME儘管rootViewController和coverImageViewController的框架都是0,0,320,480。 這意味着圖像最終會以模態方式顯示在狀態欄下方,並被壓縮20個像素。

我懷疑是UILayoutContainerView以某種方式在轉換中發生了變化,但我不確定如何確認它以及如何停止它。

任何幫助,將不勝感激。 謝謝。

這是源:

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{ 
    // Get the cover image (320x480) from the main bundle and put it in an image view. 
    UIImage *coverImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"CoverPage.png" ofType:nil]]; 
    UIImageView *coverImageView = [[UIImageView alloc] initWithImage:coverImage]; 

    // Instantiate and set up the coverImageViewController. 
    coverImageViewController = [[UIViewController alloc] init]; 

    // Desperate attempts to make image display below the status bar. 
    [coverImageViewController setModalPresentationStyle:UIModalPresentationFullScreen]; 
    [coverImageViewController wantsFullScreenLayout]; 
    [_window.rootViewController wantsFullScreenLayout]; 

    [coverImageViewController setView:coverImageView]; 

    // Make the window visible. Without a visible window the modal view won't come up. 
    [_window makeKeyAndVisible]; 

    // At this point I am sure that both the rootViewController and the coverImageViewController frames are 0,0,320,480 
    // Display the coverImageViewController modally. 
    [self.window.rootViewController presentViewController:coverImageViewController animated:NO completion:nil]; 
} 

我做了一個測試選項卡欄基於故事板項目中,我把同樣的代碼在appDelegate.m的didFinishLaunchingWithOptions方法。

它有同樣的問題。

我使用黑色透明狀態欄和獨特圖案的Default.png圖像啓動應用程序,以清楚地顯示它顯示在狀態欄下方。

一旦didFinishLaunching presentViewController被調用,它清楚地看到相同的圖案封面圖像收縮20像素(我也證實這與NSLog輸出),並顯示在下面,而不是在狀態欄下方。

希望有人知道爲什麼presentViewController會這樣做,以及如何以非機械方式阻止它。

再次感謝。 張志賢

鏈接到測試項目: http://dl.dropbox.com/u/1792284/ModalSplashTest.zip

回答

0

我決定今天上午再次看看它,並決定在調用presentViewController之前,最簡單的(如果稍微笨拙的)方法是在調用presentViewController之前調用setStatusBarHidden:YES:在調用之後的行上:NO。 這具有在半透明狀態欄下方顯示模態視圖的效果。

0

試試這個,添加圖像你已經呈現模態之後...

+0

不幸的是移動[coverImageViewController setView:coverImageView];在presentViewController調用下面沒有區別。奇怪,真的。我不會指望它可以工作。 –

+0

Humm,有時可以工作。因爲只有在製作presentViewController時,viewDidLoad纔會真正完成。如果您在此之前設置圖像,可能會出現奇怪的情況。 – Peres

相關問題