由於問題導致我無法在主要的UIWindow
中顯示內容,因此我在應用程序中添加了第二個UIWindow
。我知道這不是建議的,但我有點被迫走這條路。第二個UIWindow中的方向更改
無論如何,我創建了第二個UIWindow
,但我現在試圖設置它以響應方向更改,因爲它不會自動執行此操作,與主窗口不同。問題是我對iOS特定編碼方面的經驗不多,而且我對此有點不知所措。
這是我這麼遠:
// Create the new UIWindow
mWindow = [[UIWindow alloc] initWithFrame: CGRectMake(0, 0, size.height, size.width)];
mWindow.windowLevel = UIWindowLevelStatusBar + 1.0f;
[mP3NMoreGamesWindow setRootViewController:mMyViewController];
MyViewController定位特定的功能:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations.
NSString * supported_orientation = [Utilities GetDeviceOrientation];
if ([supported_orientation isEqualToString:@"landscape"] && (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight))
{
return YES;
}
else if ([supported_orientation isEqualToString:@"portrait"] && (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))
{
return YES;
}
return NO;
}
- (BOOL)shouldAutorotate
{
//returns true if want to allow orientation change
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
NSString * supported_orientation = [Utilities GetDeviceOrientation];
if ([supported_orientation isEqualToString:@"landscape"])
{
return UIInterfaceOrientationMaskLandscape;
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
有什麼我失蹤?我的印象是,窗口的rootviewcontroller
收到方向更改通知?
另外,是否可以在創建時設置UIWindow
的方向?例如,如果當我創建UIWindow
時當前的方向是風景,我可以將UIWindowfi
設置爲橫向,而不是縱向默認的縱向?
謝謝。
檢查並旋轉後調用這些函數。我認爲實際的問題是新UIWindow在設置時沒有考慮當前的方向。例如,創建第二個UIWindow時,該應用處於橫向模式,但創建的UIWindow隱式設置爲縱向。是否可以在創建時直接設置窗口的方向? – Benzino