【问题标题】:xcode objective c UIImageView animation lagging on startupxcode目标c UIImageView动画在启动时滞后
【发布时间】:2014-06-30 02:02:25
【问题描述】:

有一个非常奇怪的问题。我有一个通过 NSTimer 随机移动的 UIImageView。运动运行相当顺利,没有任何问题,但由于某种原因,当视图加载动画时,动画将开始,然后重置并重新开始,使其看起来滞后且不专业。知道可能是什么原因造成的吗?我之前遇到过这个问题,并且更改时间间隔然后将其更改回来似乎可以解决它,但这现在不起作用。非常感谢任何帮助,因为这真的让我很沮丧。

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    fScale = CGPointMake(.99, 1.01);
    df = CGPointMake(1,.5);
    fTimer = [NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:@selector(fMove) userInfo:nil repeats:YES];
}
-(void)fMove
{
    form.center = CGPointMake(form.center.x +df.x, form.center.y + df.y);
    if (df.x <.15 && df.x > -.15)
    {
        df.x *= -1/df.x;
        fScale.x = .99;
        if(df.y > 0)
            df.y = .5;
        else
            df.y = -.5;
        fScale.y = 1.01;
    }
    if (df.x < .5 && df.x > -.5)
    {
        fScale.x *= .995;
        fScale.y *= .995;
    }
    if (form.center.x < 100 || form.center.x >220)
        df.x *= -1;
    if (form.center.y <10 || form.center.y >530)
        df.y *= -1;



    df.x *= fScale.x;
    df.y *= fScale.y;
}

【问题讨论】:

    标签: ios objective-c xcode animation uiimageview


    【解决方案1】:

    只是一个想法。 ViewDidLoad 在加载 viewController 的 view 属性时被调用。在将视图添加到视图层次结构并可见之前可能需要一段时间(就您的应用而言),但您会立即启动计时器。也许将计时器的开始移动到 viewDidAppear 会有所作为。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      • 2013-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多