简体   繁体   English

在iPhone中平稳地移动视图

[英]move the view smoothly in iPhone

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. 我使用了陀螺仪并尝试在我的应用程序中实现Panorama功能。

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, 谢谢,

Try to decrease the time interval of the NSTimer. 尝试减少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? 我们不想使CPU过载,从而减少电池寿命,对吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM