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

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -