Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you take a look at the <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/doc/c_ref/UIDeviceOrientation" rel="nofollow">UIDevice class reference</a>, you'll see the orientation enum. Two of it's values are <code>UIDeviceOrientationFaceDown</code> and <code>UIDeviceOrientationFaceUp</code>. That being said, all you have to do is register an observer to the <code>UIDeviceOrientationDidChangeNotification</code> notification, and upon call you can check the devices current orientation and handle this accordingly.</p> <pre><code>[[NSNotificationCenter defaultCenter] addObserverForName:UIDeviceOrientationDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) { UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; if (orientation == UIDeviceOrientationFaceDown) { // device facing down }else if (orientation == UIDeviceOrientationFaceUp) { // device facing up }else{ // facing some other direction } }]; </code></pre> <p>Be sure to use the following to start generating the device notifications you'll need to observe.</p> <pre><code>[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; </code></pre> <p>If you want to get more specific information about the orientation of the device, you'll need to use the Core Motion framework to get gyro data directly. With this, you can track the exact current direction the device is facing in 3D space.</p> <pre><code>_motionManager = [CMMotionManager new]; NSOperationQueue *queue = [NSOperationQueue new]; [_motionManager setGyroUpdateInterval:1.0/20.0]; [_motionManager startGyroUpdatesToQueue:queue withHandler:^(CMGyroData *gyroData, NSError *error) { NSLog(@"%@",gyroData); }]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload