在UIView动画之间添加延迟
问题描述:
我在UIView的touchesBegan方法内部有一些操作和动画,这些操作和动画在我的视图中被分类并追加为类。 我需要动画之间的一些延迟。在UIView动画之间添加延迟
代码:
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Add delay to imitate the hold for touch 1 second and if true continue
// else cancel everything
[self animateViewSize]; // Here animates the view frame
// Add delay until sizing animation ends.....
[self animateViewFlip]; // Here animates the view flip y axis
[[NSNotificationCenter defaultCenter] postNotificationName:@"A Notification" object:self];
// Notify the superview Controller that touch happened and do some operations with animations too...
// Some variables appending values for the UIView location when it touched
}
- (void) animateCardSize
{
// Animate using UIView animation
}
- (void) animateFlipView
{
// Animate flip using CABasicAnimation
}
这是基本的想法.....
谢谢。
答
你也可以在你的方法
[self performSelector:@selector(animateCardSize) withObject:nil afterDelay:(2.0f)];
//2.0 and animateCardSize as examples
答
您可以使用基于块的UIView动画这样做:
[UIView animateWithDuration:0.4 animations:^{
//Your first anim here
} completion:^(BOOL finished){
//Your second anim here
}];
感谢名单发表评论使用我有大小,所以我增加了一个基于块的动画完成代码中的第二个翻转动画,解决了一个问题。在动画开始之前和通知之前,我需要的触摸延迟如何? – 2012-07-13 13:30:12