我有一個在故事板模式下創建的通用應用程序。它設置爲自動旋轉到當前的方向。我試圖在iPhone模式下禁用某些方向,但在模擬器中測試時不起作用。故事板中的旋轉和方向問題
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return ((interfaceOrientation != UIInterfaceOrientationLandscapeRight) || (interfaceOrientation != UIInterfaceOrientationLandscapeLeft));
} else {
return YES;
}
}
此外,當iPad旋轉時,它應該通過下面的代碼,但我得到的只是一個黑屏。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
self.view = landscape;
self.view.transform = CGAffineTransformMakeRotation(deg2rad*(90));
self.view.bounds = CGRectMake(0.0, 0.0, 1024.0, 748.0);
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
self.view = landscape;
self.view.transform = CGAffineTransformMakeRotation(deg2rad*(-90));
self.view.bounds = CGRectMake(0.0, 0.0, 1024.0, 748.0);
} else {
self.view = portrait;
self.view.transform = CGAffineTransformMakeRotation(0);
self.view.bounds = CGRectMake(0.0, 0.0, 768.0, 1004.0);
}
} else {
}
}
爲什麼所有這些問題都出現在這裏?我已經嘗試了不同的Xcode項目中的代碼,沒有故事板廣告,它工作正常。發生了什麼事情,我該如何解決這個問題?