iphone - 自动旋转的回调方法,iOS和iPad

标签 iphone ipad callback autorotate

我正在开发 iPhone 游戏,我很想知道当设备强制游戏自动旋转时是否有回调函数被调用,以便我可以更改 HUD 元素。

或者我运行无限循环来检查应用程序是否已在不同的线程中旋转?问题是我不认为这是一个有效的方法。大家有什么好的解决办法吗?

最佳答案

您所要做的就是:

在你的didfinishlaunching中写下这个

[[UIDevice currentDevice] beginGenerateDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self 选择器:@selector(didRotate:) 名称:UIDeviceOrientationDidChangeNotification 对象:nil];

然后复制下面的回调方法

- (void) didRotate:(NSNotification *)notification
{   
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

    if (orientation == UIDeviceOrientationLandscapeLeft)
    {
        NSLog(@"Landscape Left!");
        self.isLandscapeLeft=1;
    }else if(orientation == UIDeviceOrientationLandscapeRight){
         NSLog(@"Landscape Right!");
        self.isLandscapeLeft=0;
    }
}

同样,您可以检查肖像模式的方向,面朝上、面朝下、颠倒以及横向左和横向右方向。:)

关于iphone - 自动旋转的回调方法,iOS和iPad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10731681/

相关文章:

javascript - 将变量传递给回调函数

iphone - 如何创建具有 "oversized"页面的分页UIScrollView

iphone - 如何删除 UITextView 中的单个字符

javascript - 无法使用 Node.js 服务器连接到 Google Directions API

iphone - 类似杂志的版式是如何制作的?

iphone - 调用 referenceSizeForFooterInSection 而不调用 reloadData

android - 从 sqlite 触发器调用 Java 方法 (android)

iphone - 从 Storyboard 文件/NIB 文件上的控件生成的 ID 值背后的逻辑

iphone - 更改 UITableViewCell 附件后 UITableViewCellAccessoryDe​​tailDisclosureButton 消失

iphone - 仅在选择第二个单元格后调用的 TableView 委托(delegate)方法