当iPhone处于横向时如何调用另一个视图

当iPhone处于横向时如何调用另一个视图,iphone,ios,Iphone,Ios,!![第二视图为主图库视图][1] 您好,我正在尝试在设备处于横向时调用新的视图控制器。这是一个具有滚动视图的图像库,问题是我想在不同的位置显示图像库,但我不知道如何显示。我在故事板上使用的是Xcode 4.3,所以它与我认为的旧版本有点不同 谢谢你的帮助。 ![这就是它在横向中没有代码时的外观,卷轴消失][2]这就是我调用另一个视图的原因 该死!我不允许发布图像您可以使用以下方法检测方向: [[NSNotificationCenter defaultCenter] addObserver:se

!![第二视图为主图库视图][1] 您好,我正在尝试在设备处于横向时调用新的视图控制器。这是一个具有滚动视图的图像库,问题是我想在不同的位置显示图像库,但我不知道如何显示。我在故事板上使用的是Xcode 4.3,所以它与我认为的旧版本有点不同

谢谢你的帮助。 ![这就是它在横向中没有代码时的外观,卷轴消失][2]这就是我调用另一个视图的原因


该死!我不允许发布图像

您可以使用以下方法检测方向:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
然后,您可以编写一个函数,在检测到更改时切换到新的ViewController:

-(void) detectOrientation {

    if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
    {
        if(!self->wasInLandscape)
        {
            [self performSegueWithIdentifier:@"Landscape Segue" sender:self];
            self->wasInLandscape = YES;
        }


    } else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) 
    {

        if(self->wasInLandscape)
        {
            [self dismissModalViewControllerAnimated:NO];
            self->wasInLandscape = NO;
        }

    }   
}

有了这个,我将segue设置为一个没有动画的模态segue,所以当你切换时它会自动出现。
wasInLandscape
BOOL
用于确保我们在当前位置时不会关闭或执行分段。

在故事板中创建风景视图。在检查器中添加标识符,如LandscapeView。然后,在原始视图控制器中,导入横向视图的视图控制器的头文件:

#import "LandscapeViewController.h" //Change to whatever your file is called
并修改以下方法,如下所示:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    LandscapeViewController *landscapeView = [self.storyboard instantiateViewControllerWithIdentifier:@"LandscapeView"]; //change LandscapeViewController to the correct name and change LandscapeView to the correct identifier
    landscapeView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; //Or whatever transition you want

    [self presentModalViewController:landscapeView animated:NO];
    return YES;
}
然后,在横向视图的视图控制器中,修改相同的方法,如下所示:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    [self dismissModalViewControllerAnimated:NO];
    return YES;
}

您使用的是同一个视图控制器,但有两个实例吗?因此我需要为横向视图控制器创建一个新类?settingsView.ModAltTransitionStyle=UIModAltTransitionStyleCrossBluse;------这行给我发送了一个错误,上面写着:“未声明的标识符”设置视图“我需要在LandscapeViewController.h?@user1426865中声明对不起,应该是landscapeView。我从我的一个应用程序中复制并粘贴了这个,但忘了更改它。现在我将在我的答案中编辑它。好的,现在它工作了,但是当我回到纵向视图时,选项卡栏不见了。我尝试使用:self.tabBarController.tabBar.hidden=NO;self.navigationController.navigationBar.hidden=否;但仍然没有显示任何内容。@user1426865纵向视图、横向视图或两者中是否有选项卡栏?