【问题标题】:Strange behaviour of animation in viewDidAppearviewDidAppear 中动画的奇怪行为
【发布时间】:2014-04-23 13:28:17
【问题描述】:

我正在我的应用程序中对 viewDidApepar 中的动画方法进行简单调用,故事板中动画视图的初始位置是 (10 , 5) - 几乎从主视图中隐藏。

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self doTheAnimation];    
}

并且方法包含

[UIView animateWithDuration:0.8f delay:0.0f usingSpringWithDamping:0.5f initialSpringVelocity:1.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{
     [plotView setFrame:CGRectMake(10, 40, 299, 130)];
} completion:nil];

问题:当应用程序启动时 - 一切都很好,带有很酷的“弹簧”效果,但是当我推到另一个视图并返回主视图时,动画方法是调用时,LOG 显示 plotView 已将 frame.origin 更改为 (10,40),但仍停留在 (10,5) 其在故事板上的初始位置。

【问题讨论】:

  • 所以你只想运行一次动画?
  • 尝试从 ViewWillAppear 调用该方法。
  • @Desdenova - 每次显示主视图,所以每次出现视图
  • 我已经从 ViewWillAppear 尝试过,遗憾的是没有任何变化

标签: ios uiviewanimation viewdidappear


【解决方案1】:

替换

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self doTheAnimation];    
}

-(void) viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [self doTheAnimation];    
}

【讨论】:

  • 做得很好,我应该查看苹果开发页面以获取有关此方法的更多信息。
【解决方案2】:

不要更改方法的位置,只需添加以下内容:

[plotView setFrame:CGRectMake(10, 5, 299, 130)];
[UIView animateWithDuration:0.8f delay:0.0f usingSpringWithDamping:0.5f initialSpringVelocity:1.0f options:UIViewAnimationOptionBeginFromCurrentState animations:^{
    [plotView setFrame:CGRectMake(10, 40, 299, 130)];
} completion:^{
    [plotView setFrame:CGRectMake(10, 40, 299, 130)];
}];

告诉我它是否有效:)

【讨论】:

    【解决方案3】:

    更好的是:

    [self performSelector:@selector(doTheAnimation) withObject:nil afterDelay:0.5];
    

    根据需要设置延迟。

    【讨论】:

      猜你喜欢
      • 2013-03-17
      • 2023-03-11
      • 2019-10-09
      • 2016-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多