iPad 方向不太好用
我正在创建一个横向右方向的应用程序。为此,我在 info.plist
文件中设置了初始界面方向
属性。然后,在我处理的每个视图中,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return(interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}
它在模拟器中工作正常,但在设备中其行为不同。 我的第一个观点是方向正确。有一个弹出窗口,显示纵向模式下的另一个视图。我的状态栏仍然位于横向右侧。
为了从一个视图导航到我正在使用的另一个视图。
self.window.rootViewController = self.myNav;
我有多个导航控制器并使用上面的代码添加这些控制器。 我不明白问题是什么。
任何帮助将不胜感激。
编辑:
我曾经使用过,
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
我从未在模拟器中遇到此问题,但在设备中遇到此问题,但并非每次都出现此问题。我也使用了支持的界面方向(iPad)
,并为item0
设置了Landscape(右侧主页按钮)
值。
提前致谢
I am creating an application with Landscape Right orientation. For that I set the Initial interface orientation
property in info.plist
file. Then in every view I handled
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return(interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}
It works fine in simulator but in device its behave differently.
My first view is in proper orientation. There is is popover which display another view that comes in portrait mode. Still my status bar is in Landscape Right..
For navigating from one view to another view I am using..
self.window.rootViewController = self.myNav;
I have multiple navigation Controller and adding those using the upper code.
I am not getting what is the problem.
Any help will be appreciated.
EDIT:
I had used
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
I never get this issue in simulator but getting this in device and not every time. I have used Supported interface orientations (iPad)
too and set Landscape (right home button)
value for item0
.
Thanks In advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将顶视图(在所有 xib 文件中)的“模拟指标 > 方向”属性设置为“横向”。默认为纵向。
这个问题在这里得到了很好的回答 - 横向模式仅适用于 iPhone 或 iPad .
我也有一个像你的应用程序一样只支持 UIInterfaceOrientationLandscapeRight。到目前为止我还没有遇到任何方向问题。我的窗口下只有一个 UIViewController 。这个 UIViewController 有它自己的 UITabBar,我用它来更改页面。因此,我们以不同的方式更改页面。我像你一样使用窗口的 rootViewController 属性设置我的 UIViewController ,但我又只有一个。
另外,我从来不需要做类似您包含的 [[UIDevice currentDevice] beginGenerateDeviceOrientationNotifications] 调用之类的事情。由于您只支持 LandscapeRight 方向,因此您不应该关心更改的通知。
编辑
我创建了一个示例项目,如有必要我可以发布该项目,我想我可能知道你的问题。首先 - 您是否只遇到弹出窗口内的尺寸问题?如果是这样,那么我认为不是方向让你失望,而是弹出窗口本身。我的示例项目有 3 个视图控制器。第一个通过更改窗口的 rootViewController 来加载第二个。效果很好。第二个视图控制器有一个用于打开弹出窗口的按钮。除非您在视图控制器上设置 contentSizeForPopover ,否则这将显示错误,如下所示:
看看这是否可以解决您的问题。如果是这样,还有其他方法可以控制弹出窗口的大小,但这正是我通常所做的。但是,只需知道 PopoverController 会忽略您加载的视图控制器中视图的大小。
You need to set the "Simulated Metrics > Orientation" property of your top view (in all your xib files) to be "Landscape". The default is portrait.
The question was answered pretty well here - Landscape Mode ONLY for iPhone or iPad .
I also have an app that like yours only supports UIInterfaceOrientationLandscapeRight. I haven't run into any orientation issues so far. I only have one UIViewController under the window. This UIViewController has its own UITabBar that I use to change pages. So, we change pages differently. I set my UIViewController using the rootViewController property of the window just like you, but again I only have one.
Also, I never had to do anything like the [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications] call that you included. Since you only support LandscapeRight orientation, you shouldn't care to be notified of changes.
EDIT
I created a sample project, which I can post if necessary, and I think I may know your problem. First - do you only encounter the sizing issue inside popovers? If so, then I don't think orientation is throwing you off but the popover itself. My sample project has 3 view controllers. The first loads the second by changing the window's rootViewController. That worked fine. The second view controller has a button to open a popover. This will show up wrong unless you set the contentSizeForPopover on the view controller as shown below:
See if this fixes your problem. If it does, there are other ways to control the popover size, but this is just what I typically do. However, just know that the PopoverController ignores the size of the view in the viewcontroller you load.
你有多少个视图(或 viewController)?您可能需要在所有这些视图中实现此方向逻辑?
How many views (or viewControllers) you have? You might need to implement this orientation logic in all those views??