2011-09-28 40 views
0

我已閱讀了關於此主題的所有帖子,但仍無法確定此問題。啓動時的設備定位

我在applicationDidFinishLaunching的窗口中添加了一個VC。 VC包含一個UIImageView。

我想設置基於設備方向的UIImageView的圖像,但statusBarOrientation,deviceOrientation,interfaceOrientation,我檢查的所有東西都會返回人像。

有一些簡單的我想念。

您的幫助表示讚賞。

回答

0

好吧..好像有幾個問題。 1)模擬器不能按預期持續生成方向(或方向改變)數據。另外,2)在啓動時,設備可以(或不可以)及時發送statusBarOrientation信息以讀取該信息。所以,我在應用程序委託中的didFinishLaunching方法中執行了此操作。

// add the splash IV to the window per the current orientation, then animate it away 
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait){ 
self.theSplashIV.image = [UIImage imageNamed:@"Default-Portrait~ipad.png"]; 
    self.theSplashIV.frame = CGRectMake(0, 20, 768, 1004); 
} 
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown){ 
    self.theSplashIV.image = [UIImage imageNamed:@"Default-Portrait~ipad.png"]; 
    self.theSplashIV.transform = CGAffineTransformMakeRotation(M_PI); 
    self.theSplashIV.frame = CGRectMake(0, 0, 768, 1004); 
} 
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft){ 
    self.theSplashIV.image = [UIImage imageNamed:@"Default-Landscape~ipad.png"]; 
    self.theSplashIV.transform = CGAffineTransformMakeRotation(M_PI/2); 
    self.theSplashIV.frame = CGRectMake(0, 0, 748, 1024); 
} 
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight){ 
    self.theSplashIV.image = [UIImage imageNamed:@"Default-Landscape~ipad.png"]; 
    self.theSplashIV.transform = CGAffineTransformMakeRotation(M_PI/-2); 
    self.theSplashIV.frame = CGRectMake(20, 0, 748, 1024); 
} 
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 

然後,我用延遲動畫製作了第四幕。 不是很優雅,但它的工作原理。

0

有時(不知道這是在任何情況下,或者僅僅是模擬器),應用程序將在一個方向發射,然後立即旋轉到另一定向到設備方向相匹配。

我會建議實施-[UIViewController willRotateToInterfaceOrientation:duration:]設置你的形象,應後立即調用。

+0

會給這個試試看。 – mputnamtennessee

+0

Hummm ...... iPad的推出在正確的方向,並顯示正確的默認圖像,所以這不會被調用。我需要檢測當前方向的東西,而不是變化。 – mputnamtennessee

1

你是否啓用了Info.plist中的其他方向?在Xcode 4的項目編輯器中有一個圖形編輯器。

相關問題