2010-11-18 34 views
0

J'essaie de faire glisser un UIImageView dans un UIView, et de le faire fondre en même temps. Et puis je veux qu'il disparaisse et glisse. Le code ci-dessous devrait le faire, mais ce n'est pas le cas. Au lieu de cela, la vue leftArrow est au format alpha complet lorsqu'elle glisse. Ainsi, la première animation ignore le fondu enchaîné alpha. Ensuite, la seconde animation disparaît, elle ne bouge pas la vue leftArrow. J'ai essayé beaucoup de variations (en utilisant des limites au lieu de cadres, en faisant l'animation dans une méthode de classe (par opposition à une méthode d'instance), et je ne peux pas déterminer pourquoi la vue choisit arbitrairement une chose plutôt que l'autre . ou les deux Peut-être que j'ai juste besoin yeux frais TIA, MikeLa simple chaîne d'animation UIView ne fonctionne pas

- (void) flashHorizontalArrowsForView: (UIView *)view { 
DebugLog(@" flashHorizontalArrows"); 


    float duration = 1.5f; 

    // create the views 
    UIImageView *leftArrow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"leftCouponDetailArrow.png"]]; 
    leftArrow.frame = CGRectMake(0 -leftArrow.image.size.width, 
           HORIZONTAL_ARROW_START_Y, 
           leftArrow.image.size.width, 
           leftArrow.image.size.height); 

    [view addSubview:leftArrow]; 
    leftArrow.alpha = 0.0f; 

    // animate them in... 
    [UIView beginAnimations:@"foo" context:leftArrow]; 
    [UIView setAnimationDelay: 0.0f ];  // in seconds 
    [UIView setAnimationDuration: duration ]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
    [UIView setAnimationDidStopSelector:@selector(animationReallyDidStop:finished:context:)]; 
    [UIView setAnimationDelegate:self]; 

    leftArrow.alpha = 1.0f; 

    CGRect LFrame = leftArrow.frame; 
    LFrame.origin.x += LFrame.size.width; // move it in from the left. 
    leftArrow.frame = LFrame; 

    [UIView commitAnimations]; 

    // and animate them out 
    // delay enough for the first one to finish 
    [UIView beginAnimations:@"bar" context:leftArrow]; 
    [UIView setAnimationDelay: duration+0.05 ];  // in seconds 
    [UIView setAnimationDuration: duration ]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
    [UIView setAnimationDidStopSelector:@selector(animationReallyDidStop:finished:context:)]; 
    [UIView setAnimationDelegate:self]; 
    leftArrow.alpha = 0.0f; 

    CGRect LLFrame = leftArrow.bounds; 
    LLFrame.origin.x -= LLFrame.size.width; // move it off to the left. 
    leftArrow.bounds = LLFrame; 

    [UIView commitAnimations]; 

}

+0

BTW, je suis en cours d'exécution XCode 3.2.4, et cette animation échoue avec le simulateur iPhone 4.1, et un dispositif 3.1.3. – Rayfleck

Répondre

0

solution est simple -. lorsque les premières finitions d'animation, l'ont appelé une autre méthode, comme horizontal2, et horizontal2 , faites la partie animate_them_out

- (void) flashHorizontalArrowsForView: (UIView *)view{ 
DebugLog(@" flashHorizontalArrows"); 
self.theView = view; 

float duration = 1.5f; 

// create the views 
UIImageView *left = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"leftCouponDetailArrow.png"]]; 
self.leftArrow = left; 
[left release]; 
leftArrow.tag = LEFT_ARROW_TAG; 
leftArrow.frame = CGRectMake(0 -leftArrow.image.size.width, 
          HORIZONTAL_ARROW_START_Y, 
          leftArrow.image.size.width, 
          leftArrow.image.size.height); 

[theView addSubview:leftArrow]; 
leftArrow.alpha = 0.0f; 

UIImageView *right = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rightCouponDetailArrow.png"]]; 
self.rightArrow = right; 
[right release]; 
rightArrow.tag = RIGHT_ARROW_TAG; 
rightArrow.frame = CGRectMake(view.frame.size.width, // -leftArrow.image.size.width, 
          HORIZONTAL_ARROW_START_Y, 
          leftArrow.image.size.width, 
          leftArrow.image.size.height); 

[theView addSubview:rightArrow]; 
rightArrow.alpha = 0.0f; 

// -------------------------------------------- 
// animate them in... 
[UIView beginAnimations:@"foo" context:nil]; 
[UIView setAnimationDelay: 0.0f ];  // in seconds 
[UIView setAnimationDuration: duration ]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
[UIView setAnimationDidStopSelector:@selector(horizontalPart2)]; 
[UIView setAnimationDelegate:self]; 

leftArrow.alpha = 1.0f; 
rightArrow.alpha = 1.0f; 

CGRect LFrame = leftArrow.frame; 
LFrame.origin.x += LFrame.size.width; // move it in from the left. 
leftArrow.frame = LFrame; 

CGRect RFrame = rightArrow.frame; 
RFrame.origin.x -= RFrame.size.width; // move it in from the right. 
rightArrow.frame = RFrame; 
[UIView commitAnimations]; 

}

- (void) horizontalPart2 { 

// -------------------------------------------- 
// and animate them out 
// delay enough for the first one to finish 
[UIView beginAnimations:@"bar" context:nil]; 
[UIView setAnimationDelay: 1.0f ];  // in seconds 
[UIView setAnimationDuration: 3.0f ]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
[UIView setAnimationDidStopSelector:@selector(horizontalAnimationDidStop:finished:context:)]; 
[UIView setAnimationDelegate:self]; 


CGRect LLFrame = leftArrow.frame; 
LLFrame.origin.x -= LLFrame.size.width; // move it off to the left. // THIS IS NOT HAPPENING. 
leftArrow.frame = LLFrame; 

CGRect RFrame = rightArrow.frame; 
RFrame.origin.x += RFrame.size.width; 
rightArrow.frame = RFrame; 

leftArrow.alpha = 0.0f; 
rightArrow.alpha = 0.0f; 

[UIView commitAnimations]; 

}