启动方向错误

per*_*rap 2 iphone objective-c orientation

我是StackOverflow的新手,也是Objective-c的新手.

我已经试着寻找几个星期来找到一些东西给我一些暗示该做什么,但我似乎无法通过这个问题而不问问题.感觉它应该很简单,但......

我在旋转"rootView"控制器时遇到问题.它应该在横向上显示(在我决定使用导航控制器之前它已经完成).模拟器以正确的方向显示,但它已将视图旋转90度向左旋转,因此文本从下到上,侧向读取,因此您必须向左旋转头部.视图的最左侧部分是可见的,但视图的其余部分从屏幕顶部开始.这是一个大型的程序(我发现,一般来说,使用objective-c,但仍然享受它......),但这里是我认为重要的代码区域的要点:

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

// .h file:
UIWindow *window;
wordHelper3ViewController *viewController;
UINavigationController *navigationController;
Run Code Online (Sandbox Code Playgroud)

然后在实施中:

//.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;
}
Run Code Online (Sandbox Code Playgroud)

然后我在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;
    }
}
Run Code Online (Sandbox Code Playgroud)

我实现了以下内容,看看发生了什么,我立即在启动时收到日志消息:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    if (fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"didRotate...");
    }
}
Run Code Online (Sandbox Code Playgroud)

除此之外,我不认为我在我的代码中做任何会影响视图的事情.现在,转到InterfaceBuilder:

在rootView和导航控制器的属性检查器中,方向设置为横向.对于rootView,在引用出口下,"视图"设置为文件的所有者.我还有一个附加到视图的操作(touchUpInside) - 我将其类更改为UIButton,因为当用户在后台的任何位置单击时我想要resignFirstResponder.

对于navigationController,在Referencing outlets下,它显示了从navigationController到appDelegate的连接.

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

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

唯一突出的是,当我双击窗口对象时,IT在纵向模式下以视觉方式出现.

有没有人有任何想法?

Mos*_*she 13

如果您希望启动方向与初始纵向模式不同,则需要编辑info.plist文件.添加"intial interface orientation"条目并设置所需的值.

这是一个截图:

在此输入图像描述

如果要旋转UINavigationController,则需要更多工作.有关更多信息,请参阅此类似问题.