2013-02-15 40 views
0

这个问题被问到很多人,但我还没有真正找到答案。用animateWithDuration动画是非常不可预测的

我有一些类,其中内部与动画许多其他方法

someClass.m 
@implementation 

////.. 

-(void) someAnimationWithSomeObject (someParameters...blablabla 

    [UIView animateWithDuration:0.2f 
          delay:delay 
         options:UIViewAnimationOptionCurveEaseOut 
        animations:^ 
    { 
     self.center = point; 
     self.transform = CGAffineTransformMakeRotation(_angle); 
    } 
        completion:nil)]; 
中的ViewController

-(void) someMethod1 { 
/..... 


for (int i=0; i < count; i++) { 

/...some operation with coordinates 

     [self.cardContainer addSubview:someView]; 

     [someView someAnimationWithSomeObject:someParameters withDelay:delay]; 
     delay += 0.2f; 
/... } 

[自someMethod2];

} 

-(void) someMethod2 { 
/..... 


for (int i=0; i < count; i++) { 

/...some operation with coordinates 

     [self.cardContainer addSubview:someView]; 

     [someView someAnimationWithSomeObject:someParameters withDelay:delay]; 
     delay += 0.2f; 
/... } 

} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [self someMethod1]; 

} 

当我使用此代码动画是非常难以预测的,因为当坐标呼叫someMethod2计算是最快的,然后动画。

如何使动画在第一方法来播放和然后在第二中等等

[解决]

someMethod1之后加入

[self performSelector:@selector(someMethod2) withObject:nil afterDelay:delay]; 

,需要一些校正延迟+或 -

它做得很好!

+0

是'delay'实例变量,或者你只是创造了它在由0分配'someMethod2' – 2013-02-15 21:17:19

+0

延迟的开始? someMethod1 – user2037857 2013-02-15 21:25:35

回答

0

考虑在第一个完成块中启动第二个方法。也就是说,“做这个动画;然后,它结束时,调用someMethod2,并开始下一个动画

相关问题