ios - How to know the Field of View Angle of iPhone or iPad's Camera -


in android, api provides field of view angle:

  1. camera.parameters.gethorizontalviewangle()
  2. camera.parameters.getverticalviewangle()

what's equivalent in ios? don't want pre-write values because it's not flexible.

i'm not entirely sure "horizontal" , "vertical" mean in context, think of 2 calculations, rotation "z" axis (i.e. how level horizon in photo), , how it's tilted forward , backward (i.e. rotation "x" axis, namely pointing or down). can using core motion. add project , can like:

  1. make sure import coremotion header:

    #import <coremotion/coremotion.h> 
  2. define few class properties:

    @property (nonatomic, strong) cmmotionmanager *motionmanager; @property (nonatomic, strong) nsoperationqueue *devicequeue; 
  3. start motion manager:

    - (void)startmotionmanager {     self.devicequeue = [[nsoperationqueue alloc] init];     self.motionmanager = [[cmmotionmanager alloc] init];     self.motionmanager.devicemotionupdateinterval = 5.0 / 60.0;      [self.motionmanager startdevicemotionupdatesusingreferenceframe:cmattitudereferenceframexarbitraryzvertical                                                             toqueue:self.devicequeue                                                         withhandler:^(cmdevicemotion *motion, nserror *error)     {         [[nsoperationqueue mainqueue] addoperationwithblock:^{             cgfloat x = motion.gravity.x;             cgfloat y = motion.gravity.y;             cgfloat z = motion.gravity.z;              // how rotated around z axis              cgfloat rotationangle = atan2(y, x) + m_pi_2;                  // in radians             cgfloat rotationangledegrees = rotationangle * 180.0f / m_pi;  // in degrees              // how far it tilted forward , backward              cgfloat r = sqrtf(x*x + y*y + z*z);             cgfloat tiltangle = (r == 0.0 ? 0.0 : acosf(z/r);              // in radians             cgfloat tiltangledegrees = tiltangle * 180.0f / m_pi - 90.0f); // in degrees         }];     }]; } 
  4. when done, stop motion manager:

    - (void)stopmotionmanager {     [self.motionmanager stopdevicemotionupdates];     self.motionmanager = nil;     self.devicequeue = nil; } 

i'm not doing values here, can save them in class properties can access elsewhere in app. or dispatch ui updates main queue right here. bunch of options.

since ios 5 , higher, if app supporting earlier versions might want weakly link core motion then check see ok, , if not, realize you're not going capturing orientation of device:

if ([cmmotionmanager class])  {     // ok, core motion exists } 

and, in case you're wondering arbitrary choice of twelve times per second, in event handling guide ios, suggest 10-20/second if checking orientation of device.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -