Domanda

Sto cercando di far scorrere un UIImageView in un UIView, e fade in allo stesso tempo. E poi voglio che a svanire e scivolare fuori.   Il seguente codice dovrebbe fare questo, ma non è così.  Al contrario, la vista Leftarrow è al massimo alfa quando si scivola in. Quindi la prima animazione sta saltando l'alfa fade-in. Poi la seconda animazione appena svanisce fuori, non si sposta la vista FrecciaSinistra. Ho provato un sacco di varianti (utilizzando limiti e non le cornici, che fanno l'animazione in un metodo di classe (al contrario di un metodo di istanza), e non riesco a capire perché la vista sembra di scegliere arbitrariamente una cosa da fare piuttosto che l'altro, o entrambi. Forse ho solo bisogno di occhi nuovi. 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];

}

È stato utile?

Soluzione

soluzione è semplice -. Quando i primi finiture di animazione, l'hanno chiamata un altro metodo, come horizontal2, e in horizontal2, fanno la parte 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]; 

}

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top