在UIView动画之间添加延迟

时间:2012-07-13 12:52:23

标签: objective-c animation delay

我在UIView的touchesBegan方法中有一些操作和动画,我将其子类化并在视图中作为类附加。 我需要在动画之间有一些延迟。

代码:

- (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
}

这是基本的想法......

谢谢。

2 个答案:

答案 0 :(得分:2)

您可以使用基于块的UiView动画执行此操作:

[UIView animateWithDuration:0.4 animations:^{
    //Your first anim here
} completion:^(BOOL finished){
    //Your second anim here
}];

答案 1 :(得分:1)

您也可以在您的方法中使用

[self performSelector:@selector(animateCardSize) withObject:nil afterDelay:(2.0f)];
//2.0 and animateCardSize as examples