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:
add framework
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
Post a Comment