【问题标题】:Ipad orientation is not working wellIpad 方向无法正常工作
【发布时间】:2011-08-19 02:18:51
【问题描述】:

我正在创建一个横向向右方向的应用程序。为此,我在 info.plist 文件中设置了 Initial interface orientation 属性。然后在我处理的每个视图中

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {   
    return(interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}

它在模拟器中运行良好,但在设备中表现不同。 我的第一个观点是正确的方向。有一个弹出框显示另一个以纵向模式出现的视图。我的状态栏仍然在横向右侧..

为了从一个视图导航到我正在使用的另一个视图..

self.window.rootViewController = self.myNav;

我有多个导航控制器并使用上面的代码添加那些。 我不明白是什么问题。

我们将不胜感激。

EDIT:我用过

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

我从来没有在模拟器中遇到过这个问题,但不是每次都在设备中遇到这个问题。我也使用了Supported interface orientations (iPad) 并为item0 设置了Landscape (right home button) 值。

提前致谢

【问题讨论】:

    标签: ios ipad orientation


    【解决方案1】:

    您需要将顶视图(在所有 xib 文件中)的“模拟指标 > 方向”属性设置为“横向”。默认为纵向。

    这个问题在这里得到了很好的回答 - Landscape Mode ONLY for iPhone or iPad

    我也有一个像你这样的应用程序只支持 UIInterfaceOrientationLandscapeRight。到目前为止,我还没有遇到任何方向问题。我的窗口下只有一个 UIViewController。这个 UIViewController 有它自己的 UITabBar,我用它来改变页面。因此,我们以不同的方式更改页面。我和你一样使用窗口的 rootViewController 属性设置了我的 UIViewController,但我也只有一个。

    另外,我从来不需要像您包含的 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] 调用那样做任何事情。由于您只支持 LandscapeRight 方向,因此您不必在意收到更改通知。

    编辑

    我创建了一个示例项目,如有必要,我可以发布,我想我可能知道您的问题。首先 - 您是否只在弹出框内遇到尺寸问题?如果是这样,那么我不认为方向会让你失望,而是弹出框本身。我的示例项目有 3 个视图控制器。第一个通过更改窗口的 rootViewController 加载第二个。那工作得很好。第二个视图控制器有一个按钮来打开一个弹出框。这将显示错误,除非您在视图控制器上设置 contentSizeForPopover,如下所示:

    - (IBAction) showVC3InPopover
    {
        UIViewController * vc3 = [[VC3 alloc] init];
        /** Set the contentSizeForViewInPopover property to determine how 
            large the view will be in the popover!  You can do this in the 
            init method(s) of the view controller if you prefer, it's just 
            easy to do here */
        vc3.contentSizeForViewInPopover = vc3.view.frame.size;
        [_popover release], _popover = nil;
        _popover = [[UIPopoverController alloc] initWithContentViewController:vc3];
        [vc3 release];
    
        [_popover presentPopoverFromRect:_showPopoverButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
    

    看看这是否能解决您的问题。如果是这样,还有其他方法可以控制弹出框大小,但这正是我通常所做的。但是,只要知道 PopoverController 会忽略您加载的视图控制器中的视图大小。

    【讨论】:

    • 我已经完成了在横向模式下制作 xib 文件。第一个视图运行良好。但是当我使用[self.window setRootViewController:self.navHome]; 添加新视图时,它在 ios 4.2 中出现问题。
    • 我将制作一个示例项目来尝试一下。
    • 向新视图控制器的转换发生在哪里?前任。 ViewController 1 是否有提示加载 ViewController 2 的按钮(或其他东西)?通常你会有一个 UITabBar 来改变这样的视图控制器页面。
    • 我把我的示例项目放在这里:tempfiles.net/download/201108/207606/LockedOrientation.html。它小而简单,但我希望它有助于我们的讨论并帮助您弄清楚发生了什么。如果您可以调整示例并使其具有您遇到的示例问题并重新上传,那将是理想的。
    • 此问题仅在 ios 4.2 版本中出现,相同的代码在其他 ios 版本中运行良好。 ios 4.2 甚至每次都没有创建问题.. 仍然没有解决问题。
    【解决方案2】:

    你有多少视图(或视图控制器)?您可能需要在所有这些视图中实现此方向逻辑??

    【讨论】:

    • 我已经这样做了...我在使用 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 后尝试过我从来没有在模拟器中遇到过这个问题,但是在设备中而不是每次都遇到过这个问题..
    猜你喜欢
    • 2011-06-03
    • 1970-01-01
    • 2018-08-22
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 2019-06-02
    • 2021-12-29
    相关资源
    最近更新 更多