Question

Je suis en train de glisser un UIImageView dans un UIView et fondu en même temps. Et je veux que ça se fanent et faire glisser.   Le code ci-dessous devrait le faire, mais il ne fonctionne pas.  Au lieu de cela, la vue est Leftarrow à pleine alpha quand il glisse dans. La première animation saute l'alpha fade-in. Ensuite, la seconde animation s'efface juste dehors, il ne bouge pas la vue Leftarrow. J'ai essayé beaucoup de variations (à l'aide de bornes au lieu d'images, qui font l'animation dans une méthode de classe (par opposition à une méthode d'instance), et je ne peux pas déterminer pourquoi le point de vue semble choisir arbitrairement une chose à faire plutôt que de l'autre, ou les deux. Peut-être que j'ai juste besoin de nouveaux yeux. TIA, Mike

- (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];

}

Était-ce utile?

La solution

La solution est simple - lorsque les premières finitions d'animation, l'ont appeler une autre méthode, comme horizontal2, et horizontal2, faire 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]; 

}

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top