Question

In my app, I try to move the Label when the Yaw changes.

The View is moved perfectly But not smoothly.

I used the Gyroscope & try to implement the Panorama functionality in my app.

My code is as follow:

- (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;
}

Help me to solve this.

Thank you,

Was it helpful?

Solution

Try to decrease the time interval of the NSTimer. Decrease it until you get an acceptable level of smoothness, but no less. We don't want to overload the CPU, hence decrease the battery life, do we?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top