iOS 6 - How to run custom code when orientation changes

前端 未结 1 1262
梦如初夏
梦如初夏 2020-12-16 17:06

I\'m creating a game that allows the device to be in either landscape-left or landscape-right orientation, and the player can change the orientation while it\'s paused. Whe

相关标签:
1条回答
  • 2020-12-16 17:48

    Listen for device orientation changes:

    [[NSNotificationCenter defaultCenter] 
           addObserver:self
              selector:@selector(deviceOrientationDidChangeNotification:) 
                  name:UIDeviceOrientationDidChangeNotification 
                object:nil];
    

    When notified, get the device orientation from UIDevice:

    - (void)deviceOrientationDidChangeNotification:(NSNotification*)note
    {
        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
        switch (orientation)
        {
            // etc... 
        }
    }
    
    0 讨论(0)
提交回复
热议问题