即使它的风景,iPad模态视图控制器在纵向行动 [英] iPad modal view controller acting in portrait even though it's landscape

查看:80
本文介绍了即使它的风景,iPad模态视图控制器在纵向行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在横向模式下呈现ModalViewController时遇到了一些困难。基本上它以正确的界面方向显示,只有在设备处于横向模式时才会旋转,但是视图控制器就像是处于纵向模式一样。



我是呈现这样的



中的模态

   - (BOOL)应用:(UIApplication的*)应用didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions 
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//在应用程序启动后覆盖自定义点。
self.viewController = [[ViewController alloc] initWithNibName:@ViewControllerbundle:nil];
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];

LoginViewController * lvc = [[LoginViewController alloc] initWithNibName:@LoginViewControllerbundle:[NSBundle mainBundle]];
[self.window.rootViewController presentModalViewController:lvc animated:NO];

返回YES;
}

在LoginViewController中

   - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
//返回YES用于支撑取向
的NSLog(@ %@,NSStringFromCGRect( self.view.frame));
返回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 Orien tationTest [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,它会按预期工作,因此存在一些问题仅限全屏模式



第二次修改:



我已经删除了代码基础知识。我甚至不再提供模态视图控制器只是将该视图控制器初始化为根视图控制器并且仍然发生这种情况。



应用代理:



'pre> - (BOOL)应用:(UIApplication的*)应用didFinishLaunchingWithOptions:(NSDictionary的*)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//在应用程序启动后覆盖自定义点。
self.viewController = [[ViewController alloc] initWithNibName:@ViewControllerbundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
返回YES;
}

在我的视图控制器中:



'pre> - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//返回YES用于支撑取向
的NSLog(@ %@ ,NSStringFromCGRect(self.view.frame));
返回UIInterfaceOrientationIsLandscape(interfaceOrientation);
}


解决方案

好的,所以我终于找到了一种正确工作的方法。看起来如果你只是创建一个新的视图控制器并表明它将始终被反转。我找到的修复程序是将视图控制器放在导航控制器中。

  LoginViewController * lvc = [[LoginViewController alloc] initWithNibName: @LoginViewController包:[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];


I'm having some difficulty presenting a ModalViewController in landscape mode. Basically it shows up in the proper interface orientation and rotates only when the device is held in landscape mode but the viewcontroller acts as if it is in portrait mode.

I'm presenting the modal like this

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

In LoginViewController

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

The log results after a couple of rotations :

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

Basically the loginViewController acts as if it was in portrait mode. I have two text fields on this view and when i tap on one of them i want to move the view up so the keyboard is not displayed over the text field. In order to do this i have to modify the frame.origin.x instead of y because the axis are inverted (view is acting like portrait) and this is causing a lot of issues.

Edit :

If i change the modal presentation style on LoginViewController to UIModalPresentationPageSheet it works as intended so there is some issue with the fullscreen mode only

Second Edit:

I've stripped down the code to basics. I'm not even presenting a modal view controller anymore just initializing that view controller as the root view controller and still this is happening.

App delegate :

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

In my view controller :

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

解决方案

Ok , so i finally found a way for this to properly work. It seems if you just create a new view controller and present that it will always be inverted. The fix i found was the put the view controller in a navigation controller.

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

这篇关于即使它的风景,iPad模态视图控制器在纵向行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆