ios - Finding the current Accelerometer values -


i'm trying label rotate based on tit of device in app i'm making in swift. given should fine rotating label, know how find current accelerometer values of iphone? example, getting print x, y , z values once every second or so.

thanks in advance.

sample code:

  1. add framework

  2. add following code in appropriate places

    import coremotion  var motionmanager = cmmotionmanager() var accelx: cgfloat = 0  // setup accelemeter detection  if motionmanager.accelerometeravailable == true {     motionmanager.startaccelerometerupdatestoqueue(nsoperationqueue(), withhandler: { (data, error) -> void in         self.outputaccelertiondata(data.acceleration)     }) }  func outputaccelertiondata (acceleration: cmacceleration) {     accelx = 0      if fabs(cgfloat(acceleration.x)) > fabs(accelx) {         accelx = cgfloat(acceleration.x)     } } 

Comments

Popular posts from this blog

python - Installing PyDev in eclipse is failed -

PHP OOP-based login system -

c# - Nested Internal Class with Readonly Hashtable throws Null ref exception.. on assignment -