Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iPad模态视图控制器以纵向方式运行,即使它';城市景观_Iphone_Objective C_Ios_Ipad_Rotation - Fatal编程技术网

Iphone iPad模态视图控制器以纵向方式运行,即使它';城市景观

Iphone iPad模态视图控制器以纵向方式运行,即使它';城市景观,iphone,objective-c,ios,ipad,rotation,Iphone,Objective C,Ios,Ipad,Rotation,我在横向模式下演示ModalViewController时遇到一些困难。基本上,它以正确的界面方向显示,并且仅当设备保持在横向模式下时才旋转,但viewcontroller的行为就好像它处于纵向模式一样 我是这样呈现模态的 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindo

我在横向模式下演示ModalViewController时遇到一些困难。基本上,它以正确的界面方向显示,并且仅当设备保持在横向模式下时才旋转,但viewcontroller的行为就好像它处于纵向模式一样

我是这样呈现模态的

- (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;
}
在LoginView控制器中

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    NSLog(@"%@",NSStringFromCGRect(self.view.frame));
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}    
两次旋转后的日志结果:

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的行为就像它处于纵向模式一样。我在这个视图上有两个文本字段,当我点击其中一个时,我想向上移动视图,这样键盘就不会显示在文本字段上。为了做到这一点,我必须修改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);
}
改变这个

    - (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;
}    

x/y反转的帧是“特征”;)您缺少一个
convertRect:fromView
。看一下不同的视图

在您的情况下,需要将键盘框架的矩形转换为视图控制器的主视图。没有看到你的键盘框架,我不太清楚,但可能是这样的:

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

好的,我终于找到了一种方法让它正常工作。如果您只是创建一个新的视图控制器,并呈现它,它似乎将始终处于反转状态。我找到的修复方法是将视图控制器放在导航控制器中

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];

它也有同样的行为。此外,我希望它被锁定在横向中,这样即使它有效,也不能真正解决我的问题。您是否已将所有视图控制器中的值更改为“是”?是,它仍具有相同的行为。但即使它成功了,也毫无意义,因为该应用程序应该只在景观中运行,请尝试将其更改为返回interfaceOrientation=UIInterfaceOrientation和景观Right | UIInterfaceOrientation和景观Left;对不起,我可能不明白你在说什么。我使用的是标准的iOS键盘。画面一直在倒转,这就是我的问题。