我在橫向模式下呈現ModalViewController時遇到了一些困難。基本上,它以正確的界面方向顯示,並且只有當設備處於橫向模式時才旋轉,但視圖控制器的行爲好像處於縱向模式。iPad模式視圖控制器縱向縱向運行
2012-03-06 13:51:49.308 OrientationTest[3132:207] {{0, 0}, {1024, 748}}
2012-03-06 13:51:49.310 OrientationTest[3132:207] {{0, 0}, {1024, 748}}
2012-03-06 13:51:49.310 OrientationTest[3132:207] {{0, 0}, {1024, 748}}
2012-03-06 13:51:49.310 OrientationTest[3132:207] {{0, 0}, {1024, 748}}
2012-03-06 13:51:49.313 OrientationTest[3132:207] {{0, 20}, {1024, 748}}
2012-03-06 13:51:49.314 OrientationTest[3132:207] {{0, 0}, {748, 1024}}
2012-03-06 13:51:49.315 OrientationTest[3132:207] {{20, 0}, {748, 1024}}
2012-03-06 13:51:50.991 OrientationTest[3132:207] {{20, 0}, {748, 1024}}
2012-03-06 13:51:50.991 OrientationTest[3132:207] {{20, 0}, {748, 1024}}
2012-03-06 13:51:51.647 OrientationTest[3132:207] {{20, 0}, {748, 1024}}
2012-03-06 13:51:51.648 OrientationTest[3132:207] {{0, 0}, {748, 1024}}
2012-03-06 13:51:53.481 OrientationTest[3132:207] {{0, 0}, {748, 1024}}
2012-03-06 13:51:53.482 OrientationTest[3132:207] {{0, 0}, {748, 1024}}
2012-03-06 13:51:53.897 OrientationTest[3132:207] {{0, 0}, {748, 1024}}
2012-03-06 13:51:53.898 OrientationTest[3132:207] {{20, 0}, {748, 1024}}
基本上loginViewController行爲,如果:
我幾個旋轉後
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
NSLog(@"%@",NSStringFromCGRect(self.view.frame));
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
日誌結果呈現模式這樣
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
LoginViewController *lvc = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:[NSBundle mainBundle]];
[self.window.rootViewController presentModalViewController:lvc animated:NO];
return YES;
}
在LoginViewController它是在肖像模式。我在這個視圖上有兩個文本字段,當我點擊其中的一個時,我想將視圖向上移動,因此鍵盤不顯示在文本字段上。爲了做到這一點,我不得不修改frame.origin.x而不是y,因爲軸是倒置的(視圖像人像一樣),這導致了很多問題。
編輯:
如果我改變LoginViewController模態呈現風格UIModalPresentationPageSheet它按預期工作所以有一些問題與全屏模式下
第二個編輯:
我已將代碼分解爲基本代碼。我甚至不提出一個模式視圖控制器,只是將該視圖控制器初始化爲根視圖控制器,但仍然發生這種情況。
應用程序的委託:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
在我的視圖控制器:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
NSLog(@"%@",NSStringFromCGRect(self.view.frame));
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
從它的相同行爲。此外,我希望它被鎖定在橫向,所以這是不是真的解決我的問題,即使它的工作 – TegRa 2012-03-06 12:13:37
你有沒有在所有的視圖控制器中更改值是YES? – Janub 2012-03-06 12:59:37
是的,它仍然有相同的行爲。但即使它工作也沒有意義,因爲該應用只能在風景模式下運行 – TegRa 2012-03-06 13:06:38