简体   繁体   English

要求iphone设备方向刷新

[英]ask iphone device orientation to refresh

I'm creating a puzzle game for the iphone. 我正在为iphone创建一款益智游戏。 All of my menus, etc are only in the portrait orientation, but my gameplay can be in either portrait or landscape. 我的所有菜单等都只是纵向,但我的游戏玩法可以是纵向或横向。

So when I'm in the menu and the device is being held in landscape, then when I go to the gameplay viewcontroller, it does the layout with the landscape coordinates, but the screen is still actually oriented portrait-wise: 因此,当我在菜单中并且设备被保持在横向中时,那么当我进入游戏视图控制器时,它使用横向坐标进行布局,但屏幕实际上仍然是纵向的:

在此输入图像描述

I want to force the device to re-orient the screen before I do the layout. 我想强制设备在进行布局之前重新定位屏幕。 How do I do that? 我怎么做?

right now I'm testing for device orientation like this: 现在我正在测试这样的设备方向:

- (void) viewDidLoad {
    .
    .
    .

   if (!UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
      // Run Portrait Layout
   }
   else {
      // Run Landscape Layout
   }
}

So I know that the device is returning an orientation of landscape, but the screen is still oriented portrait for some reason. 所以我知道该设备正在返回横向方向,但由于某种原因,屏幕仍然是纵向的。

Perhaps try.. 也许试试..

[UIViewController attemptRotationToDeviceOrientation];

In viewDidLoad or viewWillAppear , that should make it attempt an orientation change viewDidLoadviewWillAppear ,应该使它尝试更改方向

There are a few methods in UIViewController that you can override to catch the view-did-rotate event: UIViewController中有一些方法可以覆盖以捕获view-did-rotate事件:

– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– didRotateFromInterfaceOrientation:

Do check the UIViewController class reference 检查UIViewController类引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM