2012-03-06 62 views
4

我在橫向模式下呈現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); 
} 

回答

10

好了,我終於找到了這個正常工作的一種方式。看起來,如果你只是創建一個新的視圖控制器,並表示它將始終被顛倒。我發現的修復是把視圖控制器放在導航控制器中。

LoginViewController *lvc = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:[NSBundle mainBundle]]; 
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:lvc]; 
nvc.navigationBarHidden = YES; 
lvc.modalPresentationStyle = UIModalPresentationFullScreen; 
lvc.parentView = self.navController.view; 
[self.window.rootViewController presentModalViewController:nvc animated:NO]; 
-3

改變這種

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    NSLog(@"%@",NSStringFromCGRect(self.view.frame)); 
    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
}  

這個

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    NSLog(@"%@",NSStringFromCGRect(self.view.frame)); 
    return YES; 
}  
+0

從它的相同行爲。此外,我希望它被鎖定在橫向,所以這是不是真的解決我的問題,即使它的工作 – TegRa 2012-03-06 12:13:37

+0

你有沒有在所有的視圖控制器中更改值是YES? – Janub 2012-03-06 12:59:37

+0

是的,它仍然有相同的行爲。但即使它工作也沒有意義,因爲該應用只能在風景模式下運行 – TegRa 2012-03-06 13:06:38

0

被x/y倒轉的幀是一個「特徵」;)您缺少convertRect:fromView。看看converting rects and points之間的意見。

就你而言,你需要將鍵盤框的矩形轉換爲你的視圖控制器的主視圖。沒有看到你的鍵盤邊框的東西,我不知道到底,但也可能是這樣的:

[self.view convertRect:keyboardFrame fromView:keyboardView]; 
+0

對不起,我可能不知道你在這裏說什麼。我正在使用標準的iOS鍵盤。該框架一直倒置,所以這是我的問題。 – TegRa 2012-03-06 14:31:00

相關問題