2015-01-16 23 views
0

Bonjour,iOS項目在iPhone上工作,但不在模擬器中

我的iOS項目支持風景,並在我的iPhone 4s 7.1.2上完美運行,但在模擬器中沒有。

這裏是一些截圖:

iPhone Landscape

Simulator Landscape

兩個截圖已經採取了橫向模式和模擬器似乎並沒有調整板正確

這裏我使用的代碼改變方向。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
    [UIView animateWithDuration:duration animations:^{ 

     [[UIApplication sharedApplication] setStatusBarHidden:YES]; 

     int width = [[UIScreen mainScreen] bounds].size.width - [[UIApplication sharedApplication] statusBarFrame].size.width - 10; 
     int height = width; 

     int x = 5; 
     int y = ([[UIScreen mainScreen] bounds].size.width/2) - (width/2); 

     [board setFrame:CGRectMake(x, y, width, height)]; 
    }]; 
} 
else { 
    [UIView animateWithDuration:duration animations:^{ 

     [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
     [board setFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.width)]; 
    }]; 
} 

}

感謝您的幫助:)

+0

你有沒有設置斷點,看看有什麼價值你得到? – AdamPro13

+0

據我所知,willAnimateRotationToInterfaceOrientation不能在模擬器上工作,因爲它是由iPhone設備的加速度傳感器觸發的。顯然,模擬器沒有。 – skyline75489

+0

你可以在iOS模擬器 - >硬件 - >向左旋轉/向右旋轉 – user3650409

回答

0

我沒試過你的代碼,但我堅信你所看到的是由過時的API引起的。 Official documentation here得到更多細節,以及新的API,你想要做什麼是viewWillTransitionToSize:withTransitionCoordinator:

還有一些計算器上其他一些類似這樣的問題在談論解決方案:willAnimateRotationToInterfaceOrientation not called on ios6/7

+0

You are right,willAnimateRotationToInterfaceOrientation:duration:is used in iOS 8 ... 我試過viewWillTransitionToSize:withTransitionCoordinator:它似乎可以在模擬器上正常工作。 非常感謝 – user3650409

+0

很高興提供幫助。另外,感謝給我一個「答案」標記和1UP :) – kcome

相關問題