【问题标题】:iPad - xib ignoring orientation on view loadsiPad - xib 忽略视图加载的方向
【发布时间】:2010-11-10 20:29:04
【问题描述】:

iPad 问题:

我们有从 .xibs 初始化的视图,每个 .xib 都包含横向和纵向布局。

我们加载的第一个视图尊重设备的方向,但任何后续视图似乎都对它们应该使用哪个方向感到困惑。或者,更确切地说,他们似乎完全忽略了方向,并使用保存 .xib 文件的任何方向。 (即,我们以横向保存了一个 .xib 文件,即使设备处于纵向位置,它也会从 .xib 加载具有横向布局的视图。)

这就是我们在这些视图中的调用方式:

Settings *settingsTEMP = [[Settings alloc] init];
self.settings = settingsTEMP;
[self.view insertSubview:settings.view atIndex:0];
[settingsTEMP release];

第一个调用(尊重设备方向的调用)在 viewDidLoad 中。第二个使用不同的视图(不尊重设备方向的视图)在按下按钮后调用的方法中,但使用相同的语法。

如果我们将两者都放入 viewDidLoad,它们都尊重方向。

我们已尝试搜索遇到类似问题的任何人,但迄今为止均未成功。提前感谢您提供的任何帮助。

【问题讨论】:

    标签: objective-c xcode ipad uiview interface-builder


    【解决方案1】:

    我用下面的

            
    UIInterfaceOrientation toInterfaceOrientation = self.interfaceOrientation;
    if ((toInterfaceOrientation == UIDeviceOrientationLandscapeLeft) || 
                (toInterfaceOrientation == UIDeviceOrientationLandscapeRight)) 
        {
            NSLog(@"vSettings UIDeviceOrientationLandscape");
            CGRect contentRect = CGRectMake(0,0,1024,768);
            vSettings.bounds = contentRect;
            CGRect myFrame = vSettings.frame;
            myFrame.origin.x = 0.0;
            myFrame.origin.y = 0.0;
            vSettings.frame = myFrame;
            UIImage *image;
                image = [UIImage imageNamed: @"Default-Landscape.png"];
            [backGroundSettings setImage:image];
            }
    
    

    我讨厌这样做,因为这似乎是一种正确的软糖,但它对我有用。在我创建视图之后调用。

    【讨论】:

    • 谢谢!我会试一试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-05
    • 2012-01-27
    • 1970-01-01
    • 2011-07-14
    • 2011-04-01
    • 2012-08-12
    • 2016-09-28
    相关资源
    最近更新 更多