我正在使用CMMotionManager来检索加速度计数据.问题是加速度计数据会定期打印,实例变量会在视图中更改,但视图不会重新绘制.我已经检查过hv不是零,而且一切都搞定了.在块中调用setNeedsDisplay是否有问题?
-(void) viewDidAppear:(BOOL) animated { [super viewDidAppear: animated]; [motionManager startAccelerometerUpdatesToQueue:motionQueue withHandler: ^(CMAccelerometerData *accelerometerData,NSError *error) { NSLog(@"%@",accelerometerData); HypnosisView *hv = (HypnosisView *) [self view]; hv.xShift = 10.0 * accelerometerData.acceleration.x; hv.yShift = -10.0 * accelerometerData.acceleration.y; [hv setNeedsDisplay]; }]; }