Ipad方向不能正常工作

问题描述:

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

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

它在模拟器中正常工作,但在设备中其行为不同。 我的第一个看法是正确的。有popover显示另一个肖像模式的视图。不过我的状态栏是在园林的权利..

从一个视图导航到我使用的另一种观点..

self.window.rootViewController = self.myNav; 

我有多个导航控制器及添加使用上这些代码。 我没有得到什么问题。

任何帮助将不胜感激。

EDIT:我用了

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 

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

在此先感谢

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

+0

我这个已经做... 我使用后试图'[的UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]' 我从来没有这个问题在模拟器,但得到这个装置中,而不是每次都.. –

您需要将顶视图(在所有xib文件中)的“Simulated Metrics> Orientation”属性设置为“Landscape”。默认是肖像。

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

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

此外,我从来不需要做任何事情,比如您包括的[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]调用。由于您只支持LandscapeRight方向,因此您不应该关心被通知的变化。

编辑

我创建了一个示例项目,我可以张贴如果必要的话,我想我可能知道你的问题。首先 - 你是否只遇到弹inside内的大小问题?如果是这样,那么我认为定向不会把你扔掉,而是把弹出的东西本身扔掉。我的示例项目有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忽略了您加载的视图控制器中视图的大小。

+0

我已经以横向模式创建xib文件完成。第一个视图运行良好。但是当我使用'[self.window setRootViewController:self.navHome]添加新视图;'它在ios 4.2中遇到问题。 –

+0

我会做一个示例项目来尝试一下。 – Sam

+0

转换到新的视图控制器在哪里发生?防爆。 ViewController 1是否有一个提示加载ViewController 2的按钮(或其他)?通常你会有一个UITabBar来更改视图控制器页面。 – Sam