2014-04-23 31 views
0

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

-(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),但它仍停留在storyBoard上的初始位置(10,5)处。

+0

所以你想只运行一次动画? – Desdenova

+0

尝试从ViewWillAppear调用该方法。 –

+0

@Desdenova - 每当主视图呈现时,所以每次viewAppears – EmilDo

回答

1

更换

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

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

这样做很好,我应该检查苹果开发页面以获得关于此方法的更多信息。 – EmilDo

1

不要改变你的方法的地方,只是补充一点:

[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)]; 
}]; 

告诉我,如果它的工作原理:)

0

更好的是:

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

根据需要设置延迟。