在我的应用程序中,我尝试在 Yaw 更改时移动标签。
视图移动完美但不顺利。
我使用了陀螺仪并尝试在我的应用程序中实现全景功能。
我的代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
pre_yaw=0,xpost=11;
_motionManager = [[CMMotionManager alloc] init];
[_motionManager startDeviceMotionUpdates];
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(doSomething) userInfo:nil repeats:YES];
}
- (void)doSomething
{
_deviceMotion = [_motionManager deviceMotion];
fyaw=_deviceMotion.attitude.yaw * 180 / M_PI;
fpitch=_deviceMotion.attitude.pitch * 180 / M_PI;
froll=_deviceMotion.attitude.roll * 180 / M_PI;
self.lbl_pitch.text=[ NSString stringWithFormat:@"%.0f",fpitch];
self.lbl_yaw.text=[ NSString stringWithFormat:@"%.0f",fyaw];
self.lbl_roll.text=[ NSString stringWithFormat:@"%.0f",froll];
fyaw=fabsf(fyaw);
if (fpitch<90 && fpitch>77) {
lbl_isvalid.textColor=[UIColor blueColor];
lbl_isvalid.text=@"Valid";
if (fyaw>pre_yaw) {
float diff=fyaw-pre_yaw;
xpost=xpost+diff;
lbl_move.frame=CGRectMake(xpost, 82, 42, 21);
}
}
else{
lbl_isvalid.textColor=[UIColor redColor];
lbl_isvalid.text=@"IN-Valid";
}
pre_yaw=fyaw;
}
帮我解决这个问题。
谢谢,