Iphone 启动方向是错误的

Iphone 启动方向是错误的,iphone,objective-c,orientation,Iphone,Objective C,Orientation,我是StackOverflow的新手,也是objective-c的新手 我已经试着寻找了几个星期,现在找到一些东西,给我一个做什么的提示,但我似乎无法通过这一个不问一个问题。感觉应该很简单,但是 “rootView”控制器的旋转有问题。它应该出现在景观中(在我决定使用导航控制器之前,它就出现了)。模拟器显示在正确的方向上,但它加载了向左旋转90度的视图,因此文本从下到上、从侧面读取,因此您必须向左翘起头。视图的最左侧部分可见,但视图的其余部分从屏幕顶部延伸。这是一个很大的程序(我发现,一般来说,

我是StackOverflow的新手,也是objective-c的新手

我已经试着寻找了几个星期,现在找到一些东西,给我一个做什么的提示,但我似乎无法通过这一个不问一个问题。感觉应该很简单,但是

“rootView”控制器的旋转有问题。它应该出现在景观中(在我决定使用导航控制器之前,它就出现了)。模拟器显示在正确的方向上,但它加载了向左旋转90度的视图,因此文本从下到上、从侧面读取,因此您必须向左翘起头。视图的最左侧部分可见,但视图的其余部分从屏幕顶部延伸。这是一个很大的程序(我发现,一般来说,使用objective-c,但仍然很享受……),但我认为重要的代码区域的要点如下:

在appDelegate中,我创建了一个窗口、我的rootViewcontroller和navcontroller:

// .h file:
UIWindow *window;
wordHelper3ViewController *viewController;
UINavigationController *navigationController;
然后在实施过程中:

//.m file
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Hide status bar
    application.statusBarHidden = YES;
        // --- Add the view controller's view to the window and display.
    [window addSubview:viewController.view];
    [window addSubview:navigationController.view];
    [window makeKeyAndVisible];
    return YES;
}
然后我在dealloc中释放所有这些

在我的根视图中,我正在这样做:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
        return YES;
    } else {
        return NO;
    }
}
我实现了以下功能,以查看发生了什么,并在启动时立即收到日志消息:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    if (fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"didRotate...");
    }
}
除此之外,我认为我在代码中没有做任何会影响视图的事情。现在,我们来看InterfaceBuilder:

在rootView和导航控制器的属性检查器中,方向设置为横向。对于rootView,在referencementoutlets下,“视图”设置为文件的所有者。我还将一个操作附加到视图(touchUpInside)——我将其类更改为UIButton,因为当用户单击背景中的任何位置时,我想退出FirstResponder

对于navigationController,在引用出口下,它显示了从navigationController到我的appDelegate的连接

在主窗口xib中,导航控制器显示在列表中,视图控制器显示为其子视图

viewcontroller也会单独显示在主窗口的对象列表中

唯一让我感到突出的是,当我双击窗口对象时,它会以纵向模式出现


有人有什么想法吗?

如果希望启动方向与初始纵向模式不同,则需要编辑
info.plist
文件。为“初始接口方向”添加一个条目,并设置所需的值

以下是一个屏幕截图:


如果要旋转UINavigationController,则需要更多的工作。查看更多信息。

如果我有误解,请原谅,但这不应该吗

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){
        return YES;
    } else {
        return NO;
    }
}
真的是这样吗

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

我认为您的问题在于您正在将导航控制器作为子视图添加到窗口中,并且方向通知仅发送到“窗口”中的第一个子视图

试试这个


//.m file
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Hide status bar
    application.statusBarHidden = YES;
        // --- Add the view controller's view to the window and display.
    [window addSubview:viewController.view];
    [viewController.view addSubview:navigationController.view];
    [window makeKeyAndVisible];
    return YES;
}

这很烦人,但我已经解决了方向问题,只在“窗口”中有一个子视图,然后通过该子视图(在本例中为viewController)控制所有内容。

您介意发布一个屏幕截图吗,你的描述有点不清楚。截图发布在我的谷歌文档页面上-这里是链接:我已经做了。我的初始界面方向设置为横向(主页右键),我认为需要旋转的是UINavigationController。我来看看相关的问题,看看是否有帮助。谢谢你的关注,我很感激。嗨,我读了,但它并没有解决问题。双击时,INterface Builder中的实际窗口对象以纵向显示,当我尝试在“大小检查器”中更改尺寸时,它们将灰显,阻止我更改其值。我的直觉告诉我需要改变窗口对象的宽度和高度。有人能告诉我如何实现这一点吗?也许是通过编程实现的?您可以在IB中调整视图的大小,但需要先隐藏视图的模拟元素。(模拟状态栏和可能的导航栏)如果我错了,请纠正我,但是视图和窗口是不同的,对吗?我所有的视图都正确地显示在设计中——这是在IB中以纵向显示的窗口。窗口中似乎没有任何模拟元素。我把它们都关掉了。问题-当我将NavController的代理设置为我的应用程序代理时,方向就会混乱。是的,这实际上是我开始做的,它也做了同样的事情。然后我改变了它,因为我很难理解这个方法到底做了什么。我之所以这样说,是因为这对我来说更有意义。但是,是的,我读过的所有文档中都是这样写的,所以我会把它改回去——你说得对,谢谢。这两种方法做的事情是一样的。