2014-11-04 17 views
0

我想改變UILabel值,如果我們傾斜設備,爲此我試圖實現CMMotionManager,但它不爲我工作,這是我使用的代碼,無法實現與ios應用CMMotionManager

我在lib中添加了CoreMotion。

#import <CoreMotion/CoreMotion.h> 

CMMotionManager *motionManager = [[CMMotionManager alloc] init]; 
    motionManager.accelerometerUpdateInterval = .2; 

    [motionManager startAccelerometerUpdates]; 

    if ([motionManager isAccelerometerAvailable] == YES) 
    { 

     NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
     [queue setMaxConcurrentOperationCount:1]; 

     [motionManager startAccelerometerUpdatesToQueue:queue withHandler:^(CMAccelerometerData *data, NSError *error) 
     { 

      CMAcceleration acceleration = data.acceleration; 


      if(acceleration.y < -0.25) { // tilting the device to the right 

       [self setTextforlabel:@"right"]; 

      } else if (acceleration.y > 0.25) { // tilting the device to the left 

            [self setTextforlabel:@"left"]; 
      } 
     }]; 
    } 

什麼的問題就在這裏,isAccelerometerAvailable永遠是假的,

startAccelerometerUpdatesToQueue不會朝四周。

任何一個可以幫助我,這或有任何其他方式爲傾斜設備做。

+0

我得到了它,對於傾斜,我們需要DeviceMotion及其工作檢查我的ios 7,但不是在iOS6的,對於任何評論這個? – Rajesh 2014-11-05 05:26:26

回答

0

你的設備或刺激加速運行它刺激不工作

+0

我已檢查設備 – Rajesh 2014-11-06 06:38:49